SQLite SELECT default order with PRIMARY KEY ASC

前端 未结 2 1717
日久生厌
日久生厌 2021-01-13 05:57

I\'ve created a SQLite table using:

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

If I do:

SELECT * FROM T         


        
2条回答
  •  Happy的楠姐
    2021-01-13 06:54

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

    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.

提交回复
热议问题