SQL row return order

后端 未结 5 1603
失恋的感觉
失恋的感觉 2020-12-11 03:46

I have only used SQL rarely until recently when I began using it daily. I notice that if no \"order by\" clause is used:

  1. When selecting part of a table the row
5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-11 04:18

    If you want order, include an ORDER BY. If you don't include an ORDER BY, you're telling SQL Server:

    I don't care what order you return the rows, just return the rows

    Since you don't care, SQL Server is going to decide how to return the rows what it deems will be the most efficient manner possible right now (or according to the last time the plan for this specific query was cached). Therefore you should not rely on the behavior you observe. It can change from one run of the query to the next, with data changes, statistics changes, index changes, service packs, cumulative updates, upgrades, etc. etc. etc.

提交回复
热议问题