Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
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
Author
Message
Posted Monday, September 06, 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.

Thanks,
Sanjeev.
Post #981029
Posted Monday, September 06, 2010 5:30 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 11:52 AM
Points: 41,530, Visits: 34,446
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 2008, MVP
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