CodeBlanks Logo Icon CodeBlanks

CREATE INDEX

Create a single-column index.

CREATE INDEX

With CREATE INDEX you add an index to a column. Queries on that column speed up.

CREATE INDEX idx_email ON customers (email);

Index on the email column.

The index idx_email is created.

CREATE INDEX — details

The index name must be unique. Indexes go on frequently queried columns.

A naming pattern like idx_table_column makes it easier later to tell what each index belongs to (e.g. idx_customers_email).

Practice CREATE INDEX

Add an index on the email column of customers.

Starter code

query.sql
-- email index
CREATE INDEX idx_email

Sample solution

query.sql
CREATE INDEX idx_email ON customers (email);

Expected output

İndeks oluşturuldu

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Add ON

Question
CREATE INDEX idx_email ____ customers (email);
Answer
CREATE INDEX idx_email ON customers (email);

Explanation: ON says which table and column the index is built on.

2 How must an index name be?

  • Unique Correct answer
  • Empty
  • The same
  • Random

Explanation: The index name must be unique.

3 CREATE INDEX: match the terms

Term Meaning
CREATE INDEX create
ON on
column column
speed boost

All lessons in Intermediate