sql

Is there an "are you sure" for stored procedure execution? :)

I have a stored procedure which is doing a lot of delete. Hundreds of thousands of records. It is not going to be runnable from the application, but still, i am concerned, that one of my clients accidentally runs it (i had problems earlier due to their "curiosity") :D Yes. there are backups and stuff like that, but I was thinking .... n...

Lightweight Object->Database in python

I am in need of a lightweight way to store dictionaries of data into a database. What I need is something that: Creates a database table from a simple type description (int, float, datetime etc) Takes a dictionary object and inserts it into the database (including handling datetime objects!) If possible: Can handle basic references, s...

SQL Command Result to Dictionary C# .NET 2.0

I have a simple SQL query (using SqlCommand, SqlTransaction) in .NET 2.0 that returns a table of integer-string pairs (ID, Name). I want to get this data into a dictionary like Dictionary<int, string>. I can get the result into a DataTable, but even iterating over it, I'm not sure how to do the typing and all that stuff. I feel like t...

Dump iBatis sql in Nunit?

I saw nHibernate video during the weekend. In the tutorial, the programmer was using MBunit to test his code. One neat thing i liked about nhibernate was, if you tell nhibernate to 'showSql', it displays sql in Mbunit dialog box after the unit test. I was wondering if there is something similar for ibatis using nUnit? ...

Recursive Query Help

I have two tables in my database schema that represent an entity having a many-to-many relationship with itself. Role --------------------- +RoleID +Name RoleHasChildRole --------------------- +ParentRoleID +ChildRoleID Essentially, I need to to be able to write a query such that: Given a set of roles, return the unique set o...

Compare and find differences in two tables in Oracle

Hi! i have 2 tables: account: ID, ACC, AE_CCY, DRCR_IND, AMOUNT, MODULE flex: ID, ACC, AE_CCY, DRCR_IND, AMOUNT, MODULE I want to show differences comparing only by: AE_CCY, DRCR_IND, AMOUNT, MODULE and ACC by first 4 characters Example: ID ACC AE_CCY DRCR_IND AMOUNT MODULE -- --------- ------ -------- ------ ------ 1 734647...

Finding all related tables to a given table

Hi All, I'm working on a development with over 700 tables. I need to see a listing of all related tables to a given table. Can you reccommed a app that is able to provide such a thing. Many thanks Gillian ...

How to serve a View as CSV in ASP.NET Web Forms

I have a MS SQL view that I want to make available as a CSV download in my ASPNET Web Forms app. I am using Entity Framework for other views and tables in the project. What's the best way to enable this download? I could add a LinkButton whose click handler iterates over the view, writes its CSV form to the disk, and then serves that fi...

Sql Server xml column with Entity Framework - how to keep insignificant whitespaces

Sql server 2005 (even 2008) strips the insignificant whitespaces by default. To keep one can use the CONVERT funtction with the last argument as '1' (Ref. Article). How can we do the same thing in Entity Framework? thanks ...

Benefits of using SqlCommand.ExecuteNonQuery instead of …

a) SqlCommand.ExecuteNonQuery is used for update, insert and delete operations. Besides the fact that by using ExecuteNonQuery instead of ExecuteReader we automatically know there won’t be any query results returned, are there some other benefits/reasons why ExecuteNonQuery should be used? b) Similarly, if we want a database operation...

Preventing SQL injecting in a database class

I'm building a database class and thought it'd be a good idea to incorporate some form of SQL injection prevention (duh!). Here's the method that runs a database query: class DB { var $db_host = 'localhost'; var $db_user = 'root'; var $db_passwd = ''; var $db_name = 'whatever'; function query($sql) { ...

Changing default settings in SQL Server Enterprise

In Microsoft SQL 2008 Enterprise manager, when you right click a table to open it the option only grabs the first 1000 rows. Same thing with an edit except it limits the result to 200 rows. Is there a way to increase this in the context menu? I know I change the SQL once it loads, but I'd like to set the default value myself so I don't h...

Fill data gaps - UNION, PARTITION BY, or JOIN?

Problem There are data gaps that need to be filled. Would like to avoid UNION or PARTITION BY if possible. Query Statement The select statement reads as follows: SELECT count( r.incident_id ) AS incident_tally, r.severity_cd, r.incident_typ_cd FROM report_vw r GROUP BY r.severity_cd, r.incident_typ_cd ORDER BY r.severity_...

Querying PostgreSQL for Open-High-Low-Close (OHLC) report

I am trying to query a table in PostgreSQL 8.4.2 server for to get open-high-low-close data. The table and my first query are below. Question: Is there a way to get the same results without using subqueries as in the example query below? Perhaps using FIRST_VALUE() or LAST_VALUE() window methods? -- FIRST ATTEMPT AT OHLC SELECT con...

Problem with DB2 Over clause

I'm trying to do pagination with a very old version of DB2 and the only way I could figure out selecting a range of rows was to use the OVER command. This query provide's the correct results (the results that I want to paginate over). select MIN(REFID) as REFID, REFGROUPID from ARMS_REFERRAL where REFERRAL_ID<>'Draft' and REFERRAL_ID n...

How to code Microsoft Excel "Shift Cells Up" feature in SQL

Take a simple table like below: Column Headings: || Agent's Name || Time Logged In || Center || Row 1: Andrew || 12:30 PM || Home Base Row 2: Jeff || 7:00 AM || Virtual Base Row 3: Ryan || 6:30 PM || Test Base Now lets say that a single cell is deleted so the table now looks like this: Column Headings: || Agent's Name || Time ...

Normalise this Table?

Hello all, I am creating a social bookmarking app. I am having a re-thought of the DB design in the middle of development. Should I normalise the bookmarks table and remove the tag columns that I have into a separate table. I have 10 tags per bookmark and therefore 10 columns per record (per bookmark). It seems to me that breaking the...

Send shrink Command to Microsoft SQL Database file via Ado.net connection

How is it possible to execute a direct SQL command to an ADO.NET connected database? I want to send a DBCC SHRINKDATABASE to the SQL server, to compress the current datafile after a big deletion process. The function ObjectContext::CreateQuery returns a parser error after the DBCC command. Is there any other way to shrink the database f...

is Payment table needed when you have an invoice table like this?

this is my invoice table: Invoice Table: invoice_id creation_date due_date payment_date status enum('not paid','paid','expired') user_id total_price I wonder if it's Useful to have a payment table in order to record user payments for invoices. payment table can be like this: payment_id payment_date invoice_id ...

Executing sequential stored procedures; works in query analyzer, doesn't in my .NET application

Hello, I have an audit record table that I am writing to. I am connecting to MyDb, which has a stored procedure called 'CreateAudit', which is a passthrough stored procedure to another database on the same machine called MyOther DB with a stored procedure called 'CreatedAudit' as well. In other words in MyDB I have CreateAudit, which d...