SQL CREATE INDEX Keyword
The CREATE INDEX command is used to create indexes on columns in a table. Indexes make it faster to search for data but do not change the table’s visible structure. Indexes allow duplicate values unless defined as UNIQUE.
SQL CREATE INDEX Syntax
SQL
x
1
CREATE INDEX index_name
2
ON table_name (column1 column2 ...)
SQL CREATE INDEX Example
This creates an index named idx_lastname on the last_name column of the Patients table. It helps speed up queries that search for patients by last name.
SQL
1
1
CREATE INDEX idx_lastname
2
ON Patients (last_name)

SQL CREATE INDEX on Multiple Columns Example
To create an index on two or more columns include the column names separated by commas.
This creates a combined index on the last_name and gender columns.
SQL
1
1
CREATE INDEX idx_name_gender
2
ON Patients (last_name, gender)
