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.
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

WhatsApp