In this tutorial, we will learn how to use CREATE INDEX
statement to create an index using SQL.
An SQL CREATE INDEX
statement is used to create indexes in a table.
An INDEX
can be created by a single column or group of columns in a table.
Duplicates values are allowed using this syntax.
CREATE INDEX indexName
ON tableName(column1,column2...,columnN);
For UNIQUE
values, create an index using this syntax. Duplicate values are not allowed.
CREATE UNIQUE INDEX indexName
ON tableName(column1,column2...,columnN);
This statement below creates an INDEX
named as "Index_LastName" on the column "LastName" in the table "Customer":
CREATE INDEX Index_LastName
ON Customer(LastName);
This Statement below is used to create an INDEX
on a combination of columns,
CREATE INDEX index_CustName
ON Customer(FirstName,LastName);
DROP INDEX
statement is used to delete an index in a table.
DROP INDEX tableName.indexName;
ALTER TABLE tableName
DROP INDEX indexName;
DROP INDEX indexName;