“选择”总是按主键排序? [英] Does 'Select' always order by primary key?

查看:146
本文介绍了“选择”总是按主键排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于所有的DBA,一个基本的简单问题。



当我做一个选择,它总是保证我的结果将按主键排序,



我使用Oracle作为我的数据库。 >解决方案

不,如果你不使用order by,你不能保证任何顺序。实际上,你不能保证从一个查询到下一个查询的顺序是一样的。记住,SQL正在以基于集合的方式处理数据。现在,一个数据库实现或另一个可能发生以某种方式提供排序,但你永远不应该依赖。


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 with an 'order by'?

I'm using Oracle as my DB.

解决方案

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.

这篇关于“选择”总是按主键排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆