SQL > Data Definition Language (DDL) > Create Index Statement

As mentioned in the Index overview page, a table index helps SQL statements run faster. The syntax for creating an index is:

An SQL index is a database object that speeds up data retrieval by enabling the query engine to locate rows without scanning the entire table. You can create a simple index on one column or a composite index spanning multiple columns.

CREATE INDEX "index_name" ON "table_name" (column_name);

Note that an index can only cover one table. We cannot build an index that covers multiple tables.

Let's assume that we have the following table,

Table Customer

 Column Name  Data Type 
 First_Name  char(50) 
 Last_Name  char(50) 
 Address  char(50) 
 City  char(50) 
 Country  char(25) 
 Birth_Date  datetime 

and we want to create an index on the column Last_Name, we would type in,

CREATE INDEX IDX_CUSTOMER_LAST_NAME
ON Customer (Last_Name);

If we want to create an index on both City and Country, we would type in,

CREATE INDEX IDX_CUSTOMER_LOCATION
ON Customer (City, Country);

A simple index is an index on a single column, while a composite index is an index on two or more columns. In the examples above, IDX_CUSTOMER_LAST_NAME is a simple index because there is only one column, while IDX_CUSTOMER_LOCATION is a composite index because there are two columns.

There is no strict rule on how to name an index. The generally accepted method is to place a prefix, such as "IDX_", before an index name to avoid confusion with other database objects. It is also a good idea to provide information on which table and column(s) the index is used on.

Please note that the exact syntax for CREATE INDEX may be different for different databases. You should consult with your database reference manual for the precise syntax.

Frequently Asked Questions

What is the purpose of creating an index in SQL?

An index improves the speed of data retrieval by allowing the database engine to find rows more quickly without scanning the entire table. This is especially beneficial for large tables with millions of rows.

What is the difference between a simple index and a composite index?

A simple index is built on a single column (e.g., IDX_CUSTOMER_LAST_NAME on Last_Name), while a composite index covers two or more columns within the same table (e.g., IDX_CUSTOMER_LOCATION on City and Country).

Can a single SQL index span multiple tables?

No. An SQL index can only be created on a single table — it is not possible to build one index that covers multiple tables.

Is the CREATE INDEX syntax the same across all databases?

No. While the general concept is consistent, the exact syntax for CREATE INDEX may differ between database systems such as MySQL, Oracle, and SQL Server. Always consult your database reference manual for precise syntax.

Next: SQL DROP TABLE

This page was last updated on March 19, 2026.




Copyright © 2026   1keydata.com   All Rights Reserved     Privacy Policy     About   Contact