MySQL + SQL · Lesson 88
Indexes in MySQL
What is an Index?
An index is like the index of a book — it helps MySQL find rows fast without scanning the whole table. It speeds up SELECT and WHERE, but slightly slows INSERT/UPDATE.
Creating an Index
CREATE INDEX idx_name ON students(name);
-- now searching by name is much faster
SELECT * FROM students WHERE name = 'Aman';
Automatic Indexes
PRIMARY KEY and UNIQUE columns are indexed automatically. You add indexes on columns you search or join on often.
Removing an Index
DROP INDEX idx_name ON students;
Summary
- An index speeds up searching and joining on a column.
- Primary/unique keys are auto-indexed.
- Too many indexes slow down writes — index only what you search.