Index (SQL)
An index is a data structure that speeds up searches on a table, much like the index at the back of a book. It lets the database find rows quickly instead of scanning every row.
SQL
Without an index, finding a row by a column's value may require reading the whole table. An index on that column lets the database jump straight to the matching rows, dramatically speeding up WHERE and JOIN conditions.
Indexes are not free: they take up storage and slightly slow down INSERT, UPDATE, and DELETE, because the index must be kept in sync. Primary keys are automatically indexed.
Syntax
CREATE INDEX index_name ON table_name (column);Examples
SQL
CREATE INDEX idx_email ON users (email);Output:
Index created. Lookups by email are now faster.