SQL 添加唯一索引。SQLite3

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7836561/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 12:32:36  来源:igfitidea点击:

Add unique index. SQLite3

sqlsqliteddlunique-index

提问by I159

I need to add a unique field index to an existing table. I made this row:

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

ALTER TABLE auth_user ADD UNIQUE INDEX (email);

The table and the field are already exist. The error is:

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

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

查询错误:在“UNIQUE”附近:语法错误无法执行语句

What am I missed? Did it have any specific requirements for SQLite3?

我错过了什么?它对 SQLite3 有什么特定要求吗?

回答by Adriano Carneiro

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

Also, read the official manual:

另外,请阅读官方手册:

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

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