user256239
user256239

Reputation: 18027

create a indexed column in sqlite

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

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

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:

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

Did I miss something?

Thanks.

Upvotes: 24

Views: 29157

Answers (1)

synic
synic

Reputation: 26668

A separate query is needed:

CREATE INDEX mytest_id_idx ON mytest(id);

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

CREATE TABLE mytest(id INTEGER PRIMARY KEY);

Upvotes: 58

Related Questions