SQL CREATE INDEX
Statement
The CREATE INDEX
statement is used to create indexes in tables.
Indexes allow database applications to find data more quickly without having to read the entire table.
Index
You can create indexes in tables to query data more quickly and efficiently.
Users cannot see the indexes; they are only used to speed up searches/queries.
Note: Updating a table with indexes takes more time than updating a table without indexes because the indexes themselves also need to be updated. Therefore, it is ideal to create indexes only on columns (and tables) that are frequently searched.
SQL CREATE INDEX Syntax
Creates a simple index on a table. Duplicate values are allowed:
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.
Note: The syntax for creating indexes varies between different databases. Therefore, check the syntax for creating indexes in your database.
CREATE INDEX Example
The following SQL statement creates an index named "PIndex" on the "LastName" column of the "Persons" table:
If you want to index more than one column, you can list the column names in parentheses, separated by commas: