Does 'Select' always order by primary key?

前端 未结 6 979
无人共我
无人共我 2020-12-01 18:14

A basic simple question for all of you DBA.

When I do a select, is it always guaranteed that my result will be ordered by the primary key, or should I specify it wit

6条回答
  •  死守一世寂寞
    2020-12-01 18:57

    No, if you do not use "order by" you are not guaranteed any ordering whatsoever. In fact, you are not guaranteed that the ordering from one query to the next will be the same. Remember that SQL is dealing with data in a set based fashion. Now, one database implementation or another may happen to provide orderings in a certain way but you should never rely on that.

提交回复
热议问题