What is an index?
Indexes help speed up searching in a database. If there is no index on a column in the WHERE clause, then the SQL Server has to skim through the entire table and check each and every row to find matches, which may result in slow operation on large data.
Indexes are used to find all rows matching with some columns and then to skim through only those subsets of the data to find the matches.
Syntax:
CREATE INDEX INDEX_NAME ON TABLE_NAME (COLUMN)
Explain the types of indexes
Single-column Indexes: A single-column index is created for only one column of a table.
Syntax:
CREATE INDEX index_name
ON table_name(column_name);
Composite-column Indexes: A composite-column index is created for two or more columns of a table.
Syntax:
CREATE INDEX index_name
ON table_name (column1, column2)
Unique Indexes: A unique index is used for maintaining the data integrity of a table. A unique index does not allow multiple values to be inserted into the table.
Syntax:
CREATE UNIQUE INDEX index
ON table_name(column_name)