带“选择*"的默认SQL结果排序顺序是什么? [英] What is the default SQL result sort order with 'select *'?
问题描述
如果执行select * from mytable
,将以什么顺序显示记录?它会采用第一列还是通过某种元数据对其进行排序?
If I perform a select * from mytable
, in which order will the records get displayed? Will it take the first column or order it by some sort of meta data?
我正在使用Oracle数据库.
I am using an Oracle Database.
推荐答案
默认的排序"顺序为 否 .关系表中的行未排序.
There is NO default "sort" order. Rows in a relational table are not sorted.
获取特定订单的唯一方法(实际上是唯一的方法)是使用ORDER BY
The only (really: the only) way to get a specific order is to use an ORDER BY
运行不带ORDER BY
的SELECT
时看到的任何顺序都是完全一致的,并且可以在下次执行时更改.
Whatever order you see when running a SELECT
without ORDER BY
is pure coincident and can change with the next execution.
由于各种原因,订单可能会更改:
The order can change because of various reasons:
- 其他会话运行相同的语句
- 表格已更新
- 执行计划更改
- ...
这里有一个小的SQLFiddle,它向您显示顺序"如何更改: http://sqlfiddle.com/#!4/19d14/2
Here is a little SQLFiddle that shows you how the "order" can change: http://sqlfiddle.com/#!4/19d14/2
请注意,初始的订单"甚至与插入订单都不相同!
Note that the initial "order" is not even the same as the insertion order!
这篇关于带“选择*"的默认SQL结果排序顺序是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!