Android 在sqlite中创建一个索引列

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2767571/
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-08-20 07:17:34  来源:igfitidea点击:

create a indexed column in sqlite

androidsqlite

提问by user256239

Can I create index on a column in the create table command in sqlite?

我可以在sqlite的create table命令中的列上创建索引吗?

I tried this command below in sqlite3 in Android shell. It seems to work.

我在 Android shell 的 sqlite3 中尝试了下面的这个命令。它似乎工作。

sqlite> create table mytest (id integer indexed);
sqlite> .schema
CREATE TABLE mytest (id integer indexed);

But, in sqlite's query language specification, specifying a column to be indexed is not supported:

但是,在 sqlite 的查询语言规范中,不支持指定要索引的列:

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

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

Did I miss something?

我错过了什么?

Thanks.

谢谢。

回答by synic

A separate query is needed:

需要一个单独的查询:

CREATE INDEX mytest_id_idx ON mytest(id);

Though it sounds like you want to make the idcolumn the auto increment primary key?

虽然听起来您想让该id列成为自动增量主键?

CREATE TABLE mytest(id INTEGER PRIMARY KEY);