When no 'Order by' is specified, what order does a query choose for your record set?

本秂侑毒 提交于 2019-11-26 17:44:14
marc_s

If you don't specify an ORDER BY, then there is NO ORDER defined.

The results can be returned in an arbitrary order - and that might change over time, too.

There is no "natural order" or anything like that in a relational database (at least in all that I know of). The only way to get a reliable ordering is by explicitly specifying an ORDER BY clause.

Update: for those who still don't believe me - here's two excellent blog posts that illustrate this point (with code samples!) :

With SQL Server, if no ORDER BY is specified, the results are returned in the quickest way possible.

Therefore without an ORDER BY, make no assumptions about the order.

As it was already said you should never rely on the "default order" because it doesn't exist. Anyway if you still want to know some curious details about sql server implementation you can check this out:

http://exacthelp.blogspot.co.uk/2012/10/default-order-of-select-statement-in.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!