Is an index needed for a primary key in SQLite?(SQLite 中的主键是否需要索引?)
问题描述
当一个整数列在 SQLite 表中被标记为主键时,是否也应该为它显式创建索引?SQLite 似乎不会自动为主键列创建索引,但鉴于其目的,它可能无论如何都会对其进行索引?(我会一直在那个专栏上搜索)
字符串主键的情况会有所不同吗?
它为您做到了.
一个>
<块引用>INTEGER PRIMARY KEY 列放在一边,UNIQUE 和 PRIMARY KEY约束是通过在数据库中创建索引来实现的(在与CREATE UNIQUE INDEX"语句相同的方式).这样一个索引像数据库中的任何其他索引一样用于优化查询.因此,通常没有优势(但显着的开销)在一组已经存在的列上创建索引共同受 UNIQUE 或 PRIMARY KEY 约束.
When an integer column is marked as a primary key in an SQLite table, should an index be explicitly created for it as well? SQLite does not appear to automatically create an index for a primary key column, but perhaps it indexes it anyway, given its purpose? (I will be searching on that column all the time).
Would the situation be any different for a string primary key?
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 中的主键是否需要索引?


- 在SQL中,如何为每个组选择前2行 2021-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 更改自动增量起始编号? 2021-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- SQL 临时表问题 2022-01-01