sql - 添加唯一索引。 SQLite3

标签 sql sqlite ddl unique-index

我需要向现有表添加唯一字段索引。我做了这一行:

ALTER TABLE auth_user ADD UNIQUE INDEX (email);

表和字段已经存在。 错误是:

Query Error: near "UNIQUE": syntax error Unable to execute statement

我错过了什么?它对 SQLite3 有什么具体要求吗?

最佳答案

CREATE UNIQUE INDEX IF NOT EXISTS MyUniqueIndexName ON auth_user (email)

另外,阅读官方手册:

http://www.sqlite.org/lang_createindex.html

关于sql - 添加唯一索引。 SQLite3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7836561/

相关文章:

mysql - 在带有子查询的删除语句中使用 EXISTS 代替 IN 运算符

SQL - 查询返回给定日期的事件订阅

python - 如何将默认 `db.Model` 子类化为使用 SQLAlchemy 的自定义 `Base`

python - CSV 到 sqlite3 数据库。将列表从 Utf8 转换为 unicode

sql - DDL 定义非规范化规则?

sql - 查询以查找列中数据的大小

sql - 更快的行计数 SQL Server 2008 sys.dm_db_partition_stats 与Where子句

sqlite - 在 SQLite3 中存储货币值

database - 使用带有 [template]、[encoding]、[owner] 和 .sql 文件的批处理文件创建 Postgres 数据库

sql - 什么是 DDL 和 DML?