SQLite中的主键是否需要索引?

当一个整数列在SQLite表中被标记为主键时,是否应该为它创建一个索引? SQLite似乎不会自动为主键列创建索引,但也许它索引它,无论如何,给定其目的? (我将始终在该列上搜索)。

字符串主键的情况会有什么不同吗?

It does it for you.

INTEGER PRIMARY KEY columns aside, both UNIQUE and PRIMARY KEY
constraints are implemented by creating an index in the database (in
the same way as a “CREATE UNIQUE INDEX” statement would). Such an
index is used like any other index in the database to optimize
queries. As a result, there often no advantage (but significant
overhead) in creating an index on a set of columns that are already
collectively subject to a UNIQUE or PRIMARY KEY constraint.

http://stackoverflow.com/questions/3379292/is-an-index-needed-for-a-primary-key-in-sqlite

本站文章除注明转载外,均为本站原创或编译
转载请明显位置注明出处:SQLite中的主键是否需要索引?