English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

SQL CREATE UNIQUE INDEX keyword usage and example

SQL Keywords Reference

CREATE UNIQUE INDEX (Create a unique index)

The CREATE UNIQUE INDEX command creates a unique index on the table (does not allow duplicate values)

Indexes are used to retrieve data from the database very quickly. Users do not see indexes; they are only used to speed up searches/Query.

The following SQL creates an index named 'uidx_pid' on the 'PersonID' column of the 'Persons' table:

CREATE UNIQUE INDEX uidx_pid
ON Persons (PersonID);

Note:The syntax for creating indexes varies between databases. Therefore: Check the syntax used to create indexes in the database.

Note:Updating a table using an index takes more time than updating a table without an index (because the index also needs to be updated). Therefore, it is recommended to create indexes only on columns that are frequently searched.

SQL Keywords Reference