Difference between INT PRIMARY KEY and INTEGER PRIMARY KEY SQLite

后端 未结 3 1526
醉酒成梦
醉酒成梦 2020-12-13 09:08

Is there any difference between INT PRIMARY KEY and INTEGER PRIMARY KEY when defining a schema for a table? When int primary key is used, I got

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-13 09:55

    Yes, there is a difference: INTEGER is a special case in SQLite, when the database does not create a separate primary key, but reuses the ROWID column instead. When you use INT (or any other type that "maps" to INTEGER internally) a separate primary key is created.

    That is why you see sqlite_autoindex created for the INT primary key, and no index created for the one of type INTEGER: SQLite reuses a built-in indexing structure for the integer primary key, rendering the autoindex unnecessary.

    That is why the INTEGER primary key is more economical, both in terms of storage and in terms of performance.

    See this link for details.

提交回复
热议问题