带主键ASC的SQLite SELECT默认顺序 [英] SQLite SELECT default order with PRIMARY KEY ASC

查看:410
本文介绍了带主键ASC的SQLite SELECT默认顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下方法创建了一个SQLite表:

I've created a SQLite table using:

CREATE TABLE T1 (
  CN INTEGER PRIMARY KEY ASC,
  Name TEXT
);

如果我这样做:

SELECT * FROM T1

即使不指定ORDER BY子句,我也会按CN获得行顺序吗? CN是ROWID的别名吗?

Will I get the rows order by CN even without specifying a ORDER BY clause? Is CN an alias to ROWID?

推荐答案

没有默认顺序这样的东西,如果您需要将结果排序,请添加一个显式的order by子句.

There is no such thing as a default order, if you need your results ordered add an explicit order by clause.

仅对dbms进行了优化,以寻找基于查询快速获取所需数据的最佳方法.在这种情况下,它是CN上的主键,但这仅是因为您的示例非常简单.永远不要依赖dbms选择所需的顺序.

The dbms is simply optimised to look for the best way to quickly get the required data based on the query. In this case it's the primary key on CN, but that's only because your example is so simple. Never ever rely on the dbms choosing the order you want.

这篇关于带主键ASC的SQLite SELECT默认顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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