Sql Create Index
# SQL CREATE INDEX Statement
* * *
The CREATE INDEX statement is used to create indexes in tables.
Indexes allow the database application to find data fast; without reading the whole table.
* * *
## Indexes
An index can be created in a table to find the data more quickly and efficiently.
The users cannot see the indexes, they are just used to speed up searches/queries.
**Note:** Updating a table with indexes takes more time than updating a table without (because the indexes also need an update). So, it is best to create indexes only on columns (and tables) that will be frequently searched against.
### SQL CREATE INDEX Syntax
Creates an index on a table. Duplicate values are allowed:
CREATE INDEX index_name
ON table_name (column_name)
### SQL CREATE UNIQUE INDEX Syntax
Creates a unique index on a table. Duplicate values are not allowed: A unique index means that two rows cannot have the same index value. Creates a unique index on a table. Duplicate values are not allowed:
CREATE UNIQUE INDEX index_name
ON table_name (column_name)
**Note:** The syntax for creating indexes varies amongst different databases. Therefore: Check the syntax for creating indexes in your database.
* * *
## CREATE INDEX Examples
The following SQL statement creates an index named "PIndex" on the "LastName" column in the "Persons" table:
CREATE INDEX PIndex
ON Persons (LastName)
If you want to create an index on more than one column, you can list the column names within the parentheses, separated by commas:
CREATE INDEX PIndex
ON Persons (LastName, FirstName)
YouTip