;

SQL INDEX


In this tutorial, we will learn how to use CREATE INDEX statement to create an index using SQL.

SQL CREATE INDEX statements

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.

Syntax of CREATE INDEX

Duplicates values are allowed using this syntax.

Syntax - CREATE INDEX statement
CREATE INDEX indexName
ON tableName(column1,column2...,columnN);

Syntax of CREATE UNIQUE INDEX

For UNIQUE values, create an index using this syntax. Duplicate values are not allowed.

Syntax - CREATE UNIQUE INDEX statement
CREATE UNIQUE INDEX indexName
ON tableName(column1,column2...,columnN);

Examples

This statement below creates an INDEX named as "Index_LastName" on the column "LastName" in the table "Customer":

Example - CREATE INDEX on Single column
CREATE INDEX Index_LastName
ON Customer(LastName);

This Statement below is used to create an INDEX on a combination of columns,

Syntax - CREATE INDEX on a combination of columns
CREATE INDEX index_CustName
ON Customer(FirstName,LastName);

SQL DROP INDEX Statement

DROP INDEX statement is used to delete an index in a table.

SQL Server

Syntax - DROP INDEX - SQL Server
DROP INDEX tableName.indexName;

MySQL

Syntax - DROP INDEX - MySQL
ALTER TABLE tableName
DROP INDEX indexName;

Oracle

Syntax - DROP INDEX - Oracle
DROP INDEX indexName;