Click here to monitor SSC
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in
Home       Members    Calendar    Who's On

Add to briefcase

How to extract records when table does not have unique column? Expand / Collapse
Posted Monday, September 6, 2010 5:07 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Monday, May 20, 2013 6:07 AM
Points: 78, Visits: 171
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.

Post #981029
Posted Monday, September 6, 2010 5:30 AM



Group: General Forum Members
Last Login: Yesterday @ 5:18 AM
Points: 45,619, Visits: 44,147
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

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #981046
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse