Do not specify an order by in SQL, sort by the primary key? The answer is not necessarily. As an example:
Query Attendanceemprank table, primary key is Attendanceemployeerankid, and is clustered index
Execute the following statement and find that the first sentence does not specify an order by result is not the same as the second sentence.
Looking at the execution plan, we can see that the first sentence uses the date index, and the second sentence uses the primary key index.
Look at another set of SQL and query results:
The indexes used in the execution plan are also different:
So it comes to the conclusion that, without specifying an order BY, SQL Server gets the data based on the actual query method of the execution plan, and the execution plan uses different indexes based on a number of factors in the SQL (query column, where condition, order by, and so on). The end result is likely to be different.