Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create a indexed column in sqlite

Tags:

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.

like image 254
user256239 Avatar asked May 04 '10 17:05

user256239


People also ask

Does SQLite use indexes?

An index is an additional data structure that helps improve the performance of a query. SQLite uses B-tree for organizing indexes.

What are indices in SQLite database?

Advertisements. Indexes are special lookup tables that the database search engine can use to speed up data retrieval. Simply put, an index is a pointer to data in a table. An index in a database is very similar to an index in the back of a book.

Does SQLite automatically create index?

By the same token, you should also omit explicit declaration of indexes on columns declared unique or unique constraints in the table definition. SQLite3 will create these indexes automatically.

What is indexed column in SQL?

An index contains keys built from one or more columns in the table or view. These keys are stored in a structure (B-tree) that enables SQL Server to find the row or rows associated with the key values quickly and efficiently. SQL Server documentation uses the term B-tree generally in reference to indexes.


1 Answers

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); 
like image 70
synic Avatar answered Oct 25 '22 16:10

synic