Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between CREATE INDEX AND CREATE UNIQUE INDEX?

Tags:

android

sqlite

What is the difference between CREATE INDEX AND CREATE UNIQUE INDEX in SQLite3 used in Android OS? How do indexes work in database? How are they related to columns in the table?

like image 796
Gaurav Agarwal Avatar asked Jun 10 '12 17:06

Gaurav Agarwal


1 Answers

CREATE UNIQUE INDEX isn't just an index : it adds the constraint that all records must have a different value for this column or combination of columns. If you try to insert a record whit the same combination, an error will be raised and prevent the insert (or update).

Use UNIQUE as soon as you're sure you'll have at most one record for some kind of key (user name for example).

EDIT : Here's a link to the documentation of CREATE INDEX, it describes in detail the syntax.

like image 73
Denys Séguret Avatar answered Oct 03 '22 19:10

Denys Séguret