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

标签 sqlite indexing primary-key

当整数列被标记为 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.

关于sqlite - SQLite 中的主键是否需要索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3379292/

相关文章:

Python:Sqlite 查询中的编码

python - tensorflow 切片

sqlite - 在Core Data中,是否可以创建一个没有索引的表,然后在所有插入完成后添加索引?

mysql - 使用 IN() 时主索引不起作用吗?

mysql - 向 mysql 数据库中的所有表添加列(未知表名)

python - 排序的字典返回没有意义/python

java - 升级 SQLiteDatabase Android

android - 如何将列表作为变量添加到 sqlite 表?

mysql - 正确选择 UUID 作为主键的数据类型

list - 如何使用第二个列表中的列表值外键 id 从列表中检索 Flutter Dart 列表值