Why can't you use SQLite ROWID as a Primary key?

前端 未结 1 405
面向向阳花
面向向阳花 2021-02-07 13:00

This does not execute:

create table TestTable (name text, age integer, primary key (ROWID))

The error message is:

11-23

相关标签:
1条回答
  • 2021-02-07 13:03

    Summary from SQLite.org:

    In SQLite, table rows normally have a 64-bit signed integer ROWID which is unique among all rows in the same table. (WITHOUT ROWID tables are the exception.)

    If a table contains a column of type INTEGER PRIMARY KEY, then that column becomes an alias for the ROWID. You can then access the ROWID using any of four different names, the original three names (ROWID, _ROWID_, or OID) or the name given to the INTEGER PRIMARY KEY column. All these names are aliases for one another and work equally well in any context.

    Just use it as the primary key.

    0 讨论(0)
提交回复
热议问题