SQL Server 2005和SQL Server 2012中的选择查询的默认排序顺序 [英] Default sort order for a select query in SQL Server 2005 and SQL Server 2012
问题描述
SQL Server 2005和SQL Server 2012中的选择查询的默认排序顺序之间是否有区别?
Is there a difference between default sort order for a select query in SQL Server 2005 and SQL Server 2012?
我有一个没有主键的表变量.当我在SQL Server 2005中的表变量上执行选择查询时,记录将被选择并按字母顺序按列之一显示.在SQL Server 2012中,记录的显示顺序与父表中显示的顺序相同.
I have a table variable without a primary key. When I execute a select query on the table variable in SQL Server 2005, the records are selected and displayed in alphabetical order as per one of the columns. In SQL Server 2012, the records are displayed in the same order as in the parent table.
推荐答案
没有默认的排序顺序.除非您在ORDER BY
子句中指定,否则不能保证始终以相同的方式返回结果.
There is no default sort order. Unless you specify it in the ORDER BY
clause, there is no guarantee that the result will be returned the same way all the time.
您可能会发现结果是按PK
或聚集索引排序的,但情况并非总是如此.
You might observe that the result is ordered by the PK
or the clustered index, but that's not always going to be the case.
您可能需要阅读以下内容: