Primary Key Sorting

后端 未结 7 672
醉话见心
醉话见心 2020-12-16 03:48

Is a table intrinsically sorted by it\'s primary key? If I have a table with the primary key on a BigInt identity column can I trust that queries will always return the dat

7条回答
  •  余生分开走
    2020-12-16 04:20

    You must apply the ORDER BY to guarantee an order. If you are noticing a performance difference than it is likely your data was not sorted without the ORDER BY in place — otherwise SQL-Server must be behaving badly since it is not realizing the data is already sorted. Adding the ORDER BY on already sorted data should not incur a performance penalty since the RDBMS should be smart enough to realize the order of the data.

提交回复
热议问题