SQL - Indexes: The CREATE INDEX Command
SQL - Indexes: The CREATE INDEX Command
SQL - INDEXES
https://www.tutorialspoint.com/sql/sql-indexes.htm Copyright © tutorialspoint.com
Advertisements
Indexes are special lookup tables that the database search engine can use to speed up data
retrieval. Simply put, an index is a pointer to data in a table. An index in a database is very
similar to an index in the back of a book.
For example, if you want to reference all pages in a book that discusses a certain topic, you first
refer to the index, which lists all the topics alphabetically and are then referred to one or more
specific page numbers.
An index helps to speed up SELECT queries and WHERE clauses, but it slows down data
input, with the UPDATE and the INSERT statements. Indexes can be created or dropped with
no effect on the data.
Creating an index involves the CREATE INDEX statement, which allows you to name the
index, to specify the table and which column or columns to index, and to indicate whether the
index is in an ascending or descending order.
Indexes can also be unique, like the UNIQUE constraint, in that the index prevents duplicate
entries in the column or combination of columns on which there is an index.
Single-Column Indexes
A single-column index is created based on only one table column. The basic syntax is as follows.
Unique Indexes
Unique indexes are used not only for performance, but also for data integrity. A unique index
does not allow any duplicate values to be inserted into the table. The basic syntax is as follows.
Composite Indexes
A composite index is an index on two or more columns of a table. Its basic syntax is as follows.
Whether to create a single-column index or a composite index, take into consideration the
columns that you may use very frequently in a query's WHERE clause as filter conditions.
Should there be only one column used, a single-column index should be the choice. Should
there be two or more columns that are frequently used in the WHERE clause as filters, the
composite index would be the best choice.
Implicit Indexes
https://www.tutorialspoint.com/cgi-bin/printpage.cgi 1/2
30/9/2018 SQL Indexes
Implicit indexes are indexes that are automatically created by the database server when an
object is created. Indexes are automatically created for primary key constraints and unique
constraints.
You can check the INDEX Constraint chapter to see some actual examples on Indexes.
Although indexes are intended to enhance a database's performance, there are times when they
should be avoided.
The following guidelines indicate when the use of an index should be reconsidered.
Indexes should not be used on columns that contain a high number of NULL values.
https://www.tutorialspoint.com/cgi-bin/printpage.cgi 2/2