|
I have created a table and inserted data in it:
When I select from the table, will I always get this data in the order it was inserted in?
(comments are locked)
|
|
No! You MAY get it in the order it was inserted, but there is no guarantee (even with a clustered index). You must specifiy an
(comments are locked)
|
|
It's never guaranteed. Even if you have a clustered index on the table, then you may well find that it works fine until one day your DB is installed on an enterprise edition server that decides to do a merry-go-round scan. See the 'advanced scanning' section on this page.
(comments are locked)
|
|
Will you "always" get the data back in that order, NO. If you have a clustered index that is predicated on the order in which the data is inserted will you "usually" get the data back in that order, yes. But the difference between usually and always is pretty vast. I wouldn't count on it, at all. Use an ORDER BY clause to ensure the order of the data returned.
(comments are locked)
|
|
It Depends (YESSS!!!!<--FYI, Yes isn't the answer, I'm celebrating use of It Depends) If there's a clustered index on the table the order of the data returned will come back according to which field is indexed. The order of data returned by a query will not necessarily match the clustered index. The only way to guarantee that is to use ORDER BY.
Dec 17 '09 at 05:25 PM
David 1
(comments are locked)
|

