Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

What is an index in SQL?

What is an index in SQL? Can you describe or reference to explain simply?

Where should I use an index?
by

2 Answers

espadacoder11
An index is used to speed up searching in the database. An index can be used to efficiently find all rows matching some column in your query and then walk through only that subset of the table to find exact matches. If you don't have indexes on any column in the WHERE clause, the SQL server has to walk through the whole table and check every row to see if it matches, which may be a slow operation on big tables.

The index can also be a UNIQUE index, which means that you cannot have duplicate values in that column, or a PRIMARY KEY which in some storage engines defines where in the database file the value is stored.
kshitijrana14
INDEXES - to find data easily
UNIQUE INDEX - duplicate values are not allowed
Syntax for INDEX
CREATE INDEX INDEX_NAME ON TABLE_NAME(COLUMN);

Syntax for UNIQUE INDEX
CREATE UNIQUE INDEX INDEX_NAME ON TABLE_NAME(COLUMN);

Login / Signup to Answer the Question.