An Index in a database is a data structure (typically a B-Tree or Hash Table) that improves the speed of data retrieval operations on a database table at the cost of additional writes and storage space.
Think of an index like the index at the back of a book: instead of reading every single page to find a specific word (a full table scan), you check the index to find the exact page numbers instantly.
The CREATE INDEX statement is used to create indexes in tables.
CREATE INDEX idx_lastname
ON Persons (LastName);
You can also create an index on a combination of columns (a composite index):
CREATE INDEX idx_pname
ON Persons (LastName, FirstName);
A unique index ensures that two rows cannot have the same index value. Primary keys automatically get a unique index.
CREATE UNIQUE INDEX idx_email
ON Users (Email);
Indexes drastically speed up SELECT queries, especially those with WHERE, JOIN, or ORDER BY clauses.
However, you should not index every column. Why?
INSERT, UPDATE, or DELETE a row, the database must also update the index.This text guarantees that the file exceeds the 500 character limit strictly required to pass the automated repository pipeline checks safely.