Latest web development tutorials

SQL CREATE INDEX statement

CREATE INDEX statement to create an index in the table.

Without reading the whole table, the index database application can find data faster.


index

You can create an index in the table, in order to more quickly and efficiently query data.

The user can not see the indexes, they can only be used to speed up the search / query.

Note: Update table with indexes requires more than updating a table with no indexes takes more time, this is because the index itself also needs to be updated.Therefore, the ideal approach is often just searched columns (and tables) to create the index above.

SQL CREATE INDEX Syntax

Create a simple index on a table. It allows the use of duplicate values:

CREATE INDEX index_name
ON table_name (column_name)

SQL CREATE UNIQUE INDEX syntax

Create a unique index on the table. No duplicate values: unique index means that two rows can not 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 in different databases are not the same.So check your database to create the index syntax.


Examples of CREATE INDEX

The following SQL statement creates an index called "PIndex" on the "LastName" column "Persons" table:

CREATE INDEX PIndex
ON Persons (LastName)

If you want to index more than one column, you can list the names of the columns in parentheses, separated by commas:

CREATE INDEX PIndex
ON Persons (LastName, FirstName)