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.
💻 Live Code Editor
Is page ki language (MYSQL) mein code likhein aur turant chalाएं — yahीं, bina kuch install kiye.Powered by OneCompiler. Agar editor na khule to yahान naye tab mein kholein.
💻 Live Code Editor
Is page ke program yahan ready hain — chalाएं, badlें aur seekhें. Bina kuch install kiye.
Powered by OneCompiler. Editor mein code apne aap aa jata hai — Run dabaakर output dekhें.
Agar load na ho to naye tab mein kholें.