开发者

What criteria does SQL Server use to order its records, when none is specified on retrieval

开发者 https://www.devze.com 2023-01-04 16:05 出处:网络
Will the order of the record retrieved using a select query, be in the same order i开发者_如何学运维f retrieved infinite number of times, each time using a new connection? (to the same table, same sel

Will the order of the record retrieved using a select query, be in the same order i开发者_如何学运维f retrieved infinite number of times, each time using a new connection? (to the same table, same select)

What order method is used when none is specified?


If you do not define an ORDER BY clause, there's no implied ordering.

It might happen to look like it's being ordered by the primary key or the clustering key - but it's not guaranteed to be that way.

So: if you need a specific order, specify an ORDER BY.


Depends totally on the query - basically on the way it thinks it will get the query processed fastest.

Which, for all practical means, means the order is "random" (as in: not determined), per standard SQL specifications.


Will the order of the record retrieved using a select query, be in the same order if retrieved infinite number of times, each time using a new connection?

No. There is no guaranteed "natural" order.

As others have suggested, your results will often be ordered by primary key, but that's not guaranteed, and once you add JOINs there's not even that to go by.

0

精彩评论

暂无评论...
验证码 换一张
取 消