0

i would need to implement a LIMIT equivalent (from mysql) to MSSQL. I have found many topics here that answer this issue, but all require you to order by a specific column. I need to do this without having to order the table because my code is going through many tables automatically so the table structure/column names change from table to table and i dont know what table can be used to order properly.

the reason for this is that i am processing a HUGE table in vb.net and adapter.Fill(ds_values) causes to go out of memory so i would need to process the table in chunks of 1000 rows at the time..

Any help appreciated.

THanks

sharkyenergy
  • 3,842
  • 10
  • 46
  • 97

1 Answers1

1

There is no way to know in which order the records where inserted if you don't have a column indicating that. That is not how DB engines work.

The DB engine's algorithm tries to fetch the data as fast as possible. And it does not care about an order if you don't specify one.

juergen d
  • 201,996
  • 37
  • 293
  • 362
  • i think i am missing something here... what order are they read out when i execute the query without a order funciton? i thought that the latest entreis are added at the end... – sharkyenergy Oct 15 '13 at 08:55
  • The order is kind of random. You can't predict it. You would have to have the DB engine's source code to reconstruct that if you even could. – juergen d Oct 15 '13 at 08:56
  • @sharkyenergy There is no guarantee of order *except* when an `ORDER BY` is present. The results will generally be ordered based off of some physical layout (perhaps the clustered indexed) - but exactly what, and how, depends on what the query planner was feeling like. – user2864740 Oct 15 '13 at 08:56
  • @sharkyenergy You are correct. [FETCH/OFFSET](http://technet.microsoft.com/en-us/library/ms188385.aspx) are the equivalent. Be happy SQL Server is trying to guarantee predictable results. – user2864740 Oct 15 '13 at 09:01
  • this is only on version 2012. i am on 2008 – sharkyenergy Oct 15 '13 at 09:02
  • @sharkyenergy http://stackoverflow.com/questions/2135418/equivalent-of-limit-and-offset-for-sql-server – user2864740 Oct 15 '13 at 09:03