September 6, 2010 at 5:07 am
Hello -
I am in process of writing a program in c# where I need to extract records from tables. When the table has more the 1million recordsm, my query throws OutOfMemory exception. To overcome this, I modified my query to :
string sqlQuery = "Select * from " + tname + " where ID between "+ IDStart +" and " + IDEnd;
Now the problem is every table does not have ID column, this is where my query fails.
Can you suggest me a way how to extract data (something like TOP 50000) from a table where ID column does not exist?
In short, I need to extract data in chunks.
Please let me know if you need more information.
Thanks,
Sanjeev.
September 6, 2010 at 5:30 am
Look up ROW_NUMBER(), just note that it's not particularly fast on larger result sets.
p.s. Consider using parametrised SQL statements or stored procedures. That example line you gave is vulnerable to SQL Injection attacks.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply