Table indexes are created using the CREATE INDEX statement.
Data can be retrieved from the database more quickly when using indexes. The indexes are only there to speed up searches and queries; users cannot see them.
Note: Because the indexes also need to be updated, updating a table with indexes takes longer than updating a table without. Therefore, only build indexes on columns that will be used for frequent searches.
Creates an index on a table. Duplicate values are allowed:
CREATE INDEX index_name
ON table_name (column1, column2, ...);
Creates a unique index on a table. Duplicate values are not allowed:
CREATE UNIQUE INDEX index_name
ON table_name (column1, column2, ...);
An index called “idx_lastname” is created on the “LastName” column in the “Persons” database by the SQL statement that follows:
CREATE INDEX idx_lastname
ON Persons (LastName);
You can list the column names in the parenthesis, separated by commas, if you wish to establish an index on a subset of the columns:
CREATE INDEX idx_pname
ON Persons (LastName, FirstName);
A table’s index can be removed using the DROP INDEX statement.
ALTER TABLE table_name
DROP INDEX index_name;
CodingAsk.com is designed for learning and practice. Examples may be made simpler to aid understanding. Tutorials, references, and examples are regularly checked for mistakes, but we cannot guarantee complete accuracy. By using CodingAsk.com, you agree to our terms of use, cookie, and privacy policy.
Copyright 2010-2024 by Refsnes Data. All Rights Reserved.