0
0
SQLquery~20 mins

CREATE INDEX syntax in SQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Index Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the effect of this CREATE INDEX statement?
Consider the SQL statement:
CREATE INDEX idx_customer_name ON customers (last_name, first_name);

What does this statement do?
ACreates an index named idx_customer_name on the customers table using the last_name and first_name columns to speed up queries filtering or sorting by these columns.
BDeletes the customers table and replaces it with an index named idx_customer_name.
CCreates a new table named idx_customer_name with columns last_name and first_name.
DUpdates all rows in customers to have unique last_name and first_name values.
Attempts:
2 left
💡 Hint
Think about what an index does in a database.
📝 Syntax
intermediate
2:00remaining
Which CREATE INDEX statement is syntactically correct?
Choose the correct syntax to create an index named idx_order_date on the orders table for the order_date column.
ACREATE INDEX idx_order_date orders (order_date);
BCREATE INDEX idx_order_date ON orders (order_date);
CCREATE INDEX ON orders idx_order_date (order_date);
DCREATE INDEX idx_order_date ON orders order_date;
Attempts:
2 left
💡 Hint
Remember the order: CREATE INDEX index_name ON table_name (column_name);
optimization
advanced
2:00remaining
Which index will best optimize queries filtering by both city and state?
You have a customers table with columns city and state. You want to speed up queries that filter by both city and state.
Which CREATE INDEX statement is best?
ACREATE INDEX idx_state ON customers (state);
BCREATE INDEX idx_state_city ON customers (state, city);
CCREATE INDEX idx_city ON customers (city);
DCREATE INDEX idx_city_state ON customers (city, state);
Attempts:
2 left
💡 Hint
Think about the order of columns in a multi-column index.
🔧 Debug
advanced
2:00remaining
What error does this CREATE INDEX statement produce?
Consider this SQL statement:
CREATE INDEX idx_price ON products price;

What error will it cause?
ASyntax error due to missing parentheses around the column name.
BRuntime error because the products table does not exist.
CNo error; index created successfully.
DError because idx_price is a reserved keyword.
Attempts:
2 left
💡 Hint
Check the syntax for specifying columns in CREATE INDEX.
🧠 Conceptual
expert
2:00remaining
What is a key limitation of creating too many indexes on a table?
Which of the following is a main drawback of having many indexes on a database table?
AThe table schema becomes invalid and cannot be queried.
BQueries become slower because indexes confuse the query planner.
CInserts, updates, and deletes become slower because all indexes must be updated.
DIndexes automatically delete duplicate rows causing data loss.
Attempts:
2 left
💡 Hint
Think about what happens when data changes in a table with many indexes.