SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


How to extract records when table does not have unique column?


How to extract records when table does not have unique column?

Author
Message
sanjeev_krs2004
sanjeev_krs2004
Right there with Babe
Right there with Babe (718 reputation)Right there with Babe (718 reputation)Right there with Babe (718 reputation)Right there with Babe (718 reputation)Right there with Babe (718 reputation)Right there with Babe (718 reputation)Right there with Babe (718 reputation)Right there with Babe (718 reputation)

Group: General Forum Members
Points: 718 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.
GilaMonster
GilaMonster
SSC Guru
SSC Guru (470K reputation)SSC Guru (470K reputation)SSC Guru (470K reputation)SSC Guru (470K reputation)SSC Guru (470K reputation)SSC Guru (470K reputation)SSC Guru (470K reputation)SSC Guru (470K reputation)

Group: General Forum Members
Points: 470320 Visits: 47372
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


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum







































































































































































SQLServerCentral


Search