Ad space (banner)
🗄️SQL Lessons
Lesson 24 / 50

Speeding Up Searches with INDEX

This lesson covers speeding up searches with INDEX, and introduces the basic idea behind query performance on large tables. It's for anyone searching "SQL INDEX tutorial" or "what is a database index."

An index, created with CREATE INDEX, works like a book's index — it lets the database jump straight to matching rows instead of scanning the whole table, dramatically speeding up searches on columns you query often.

The example creates an index on the name column with CREATE INDEX idx_name ON students(name);. You won't feel the difference on tiny sample data, but on a table with millions of rows, having (or lacking) an index can be the difference between milliseconds and seconds.

A common early mistake is assuming more indexes are always better — they speed up reads, but every extra index also slows down inserts and updates, since the index itself has to be maintained. Learning to identify "which columns actually get searched on" and index those selectively is a genuinely important database design skill — and checking "does this column have an index" is usually the very first step when diagnosing a slow query in production.

SQL
OUTPUT

💡 The SQL engine may take a few seconds to load the first time you run code.

Ad space (banner)
Ad space (in-article)