What is an INDEX?
- SQL course
- Intermediate
- Lesson 77/115
- 4 min
Learn that an index speeds up search.
What is an INDEX?
An INDEX speeds up searches. It acts like a table of contents in a book.
CREATE INDEX idx_name ON customers (name);This query creates an index on the name column.
The index idx_name is created.
What is an INDEX? — details
An INDEX speeds up queries but slows down writes. Each INSERT/UPDATE also updates the index.
For example, on a site where users log in by email, indexing the email column makes a lookup among millions of rows almost instant.
Practice What is an INDEX?
Add an idx_name index on the name column of customers.
Starter code
-- create index
CREATE INDEXSample solution
CREATE INDEX idx_name ON customers (name);Expected output
İndeks oluşturuldu
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What does an INDEX speed up?
- Creating tables
- Writes
- Deletes
- Searches Correct answer
Explanation: An INDEX speeds up searches.
2 Add CREATE INDEX
CREATE ____ idx_name ON customers (name);
CREATE INDEX idx_name ON customers (name);
Explanation: CREATE INDEX builds an index on a column and speeds up searches.
3 What is an INDEX: match the terms
| Term | Meaning |
|---|---|
INDEX |
speeds up |
CREATE |
create |
ON |
on |
write |
slows |