What is the purpose of the CREATE INDEX statement in SQL?
It creates an index on one or more columns of a table to speed up data retrieval.
Click to reveal answer
beginner
Write the basic syntax of CREATE INDEX.
CREATE INDEX index_name ON table_name (column1, column2, ...);
Click to reveal answer
intermediate
Can you create an index on multiple columns? How?
Yes, by listing multiple columns separated by commas inside parentheses after the table name.
Click to reveal answer
intermediate
What is a unique index and how do you create it?
A unique index ensures all values in the indexed column(s) are distinct. Use CREATE UNIQUE INDEX instead of just CREATE INDEX.
Click to reveal answer
intermediate
Does creating an index affect data insertion speed? Why or why not?
Yes, because the database must update the index every time data is inserted, which adds overhead.
Click to reveal answer
What does the CREATE INDEX statement do?
ACreates a new table
BDeletes data from a table
CSpeeds up data retrieval by creating an index
DUpdates existing data
✗ Incorrect
CREATE INDEX creates an index to speed up searching data in a table.
Which of the following is the correct syntax to create an index on the column name in the table users?
ACREATE INDEX users ON name;
BCREATE INDEX idx_name ON users (name);
CCREATE INDEX name ON users;
DCREATE INDEX users_name (name);
✗ Incorrect
The correct syntax is CREATE INDEX index_name ON table_name (column_name);
How do you create a unique index?
ACREATE UNIQUE INDEX index_name ON table_name (column);
BCREATE INDEX UNIQUE index_name ON table_name (column);
CCREATE INDEX index_name UNIQUE ON table_name (column);
DCREATE INDEX index_name ON table_name UNIQUE (column);
✗ Incorrect
The correct syntax places UNIQUE right after CREATE: CREATE UNIQUE INDEX.
Can you create an index on more than one column?
ANo, indexes only work on single columns
BYes, by listing columns separated by commas inside parentheses
CYes, but only if columns are of the same data type
DNo, you must create separate indexes for each column
✗ Incorrect
You can create a multi-column index by listing columns inside parentheses separated by commas.
What is a downside of creating many indexes on a table?
AIt slows down data retrieval
BIt uses less disk space
CIt slows down data insertion and updates
DIt deletes data accidentally
✗ Incorrect
Indexes must be updated on data changes, so many indexes slow down insert and update operations.
Explain the syntax and purpose of the CREATE INDEX statement.
Think about how you tell the database to make searching faster.
You got /5 concepts.
Describe the trade-offs of using indexes in a database.
Consider both benefits and costs of indexes.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of using CREATE INDEX in a database?
easy
A. To speed up data retrieval by creating shortcuts on columns
B. To delete rows faster from a table
C. To backup the database automatically
D. To encrypt the data stored in the table
Solution
Step 1: Understand what an index does
An index creates a shortcut to quickly find data in a column without scanning the whole table.
Step 2: Identify the main benefit
This shortcut speeds up data retrieval, especially for searches and sorts.
Final Answer:
To speed up data retrieval by creating shortcuts on columns -> Option A
Quick Check:
CREATE INDEX improves search speed [OK]
Hint: Indexes speed up searches by creating shortcuts [OK]
Common Mistakes:
Thinking indexes speed up data deletion
Confusing indexes with backups
Believing indexes encrypt data
2. Which of the following is the correct syntax to create an index named idx_name on the column last_name of the table employees?
easy
A. CREATE idx_name INDEX ON employees (last_name);
B. CREATE INDEX idx_name ON employees (last_name);
C. INDEX CREATE idx_name ON employees (last_name);
D. CREATE INDEX ON employees idx_name (last_name);
Solution
Step 1: Recall the standard CREATE INDEX syntax
The correct syntax is: CREATE INDEX index_name ON table_name (column_name);
Step 2: Match the syntax with options
CREATE INDEX idx_name ON employees (last_name); matches the correct order and keywords exactly.
Final Answer:
CREATE INDEX idx_name ON employees (last_name); -> Option B
Quick Check:
CREATE INDEX index_name ON table (column) [OK]
Hint: Remember: CREATE INDEX name ON table (column) [OK]
Common Mistakes:
Swapping index name and table name positions
Using wrong keyword order
Omitting ON keyword
3. Given the table products(id INT, name VARCHAR, price DECIMAL), what will be the result of this SQL command?
CREATE INDEX idx_price ON products(price);
medium
A. The products table is duplicated with the name idx_price
B. The price column is deleted from the products table
C. An index named idx_price is created on the price column to speed up queries filtering by price
D. Syntax error because price is not a primary key
Solution
Step 1: Understand what the CREATE INDEX command does here
The command creates an index named idx_price on the price column of products.
Step 2: Identify the effect of the index
This index helps speed up queries that filter or sort by price without changing the table structure.
Final Answer:
An index named idx_price is created on the price column to speed up queries filtering by price -> Option C
Quick Check:
CREATE INDEX adds search speed, no deletion [OK]
Hint: CREATE INDEX speeds up search, does not delete or duplicate [OK]
Common Mistakes:
Thinking index creation deletes columns
Assuming index requires primary key
Confusing index with table duplication
4. Identify the error in this SQL statement:
CREATE INDEX ON employees (last_name);
medium
A. Cannot create index on last_name column
B. Missing table name after ON
C. Incorrect use of parentheses around column name
D. Missing index name after CREATE INDEX
Solution
Step 1: Check the syntax of CREATE INDEX
The syntax requires an index name after CREATE INDEX before ON.
Step 2: Identify the missing part
The statement lacks the index name, which causes a syntax error.
Final Answer:
Missing index name after CREATE INDEX -> Option D
Quick Check:
CREATE INDEX must have a name [OK]
Hint: Always name your index after CREATE INDEX [OK]
Common Mistakes:
Omitting the index name
Confusing table name with index name
Misplacing parentheses
5. You want to speed up queries that filter by both category and price columns in the items table. Which is the best way to create an index?
hard
A. CREATE INDEX idx_cat_price ON items (category, price);
B. CREATE INDEX idx_cat ON items (category); CREATE INDEX idx_price ON items (price);
C. CREATE INDEX idx_price_cat ON items (price, category);
D. CREATE INDEX idx_items ON items (category);
Solution
Step 1: Understand multi-column index usage
A single index on (category, price) helps queries filtering by both columns efficiently.
Step 2: Compare options
CREATE INDEX idx_cat_price ON items (category, price); creates a composite index on category and price in that order, which is best for combined filters.
Final Answer:
CREATE INDEX idx_cat_price ON items (category, price); -> Option A
Quick Check:
Composite index on both columns is best [OK]
Hint: Use composite index for multiple columns searched together [OK]
Common Mistakes:
Creating separate indexes instead of composite
Wrong column order in composite index
Creating index on only one column when filtering by two
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.