Challenge - 5 Problems
Unique Index Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
What is the output of this query with a unique index?
Consider a table
users with columns id (primary key) and email. A unique index is created on email. What happens when you run this insert query?MySQL
INSERT INTO users (id, email) VALUES (1, 'alice@example.com'), (2, 'bob@example.com'), (3, 'alice@example.com');
Attempts:
2 left
💡 Hint
Think about how unique indexes enforce uniqueness during batch inserts.
✗ Incorrect
A unique index prevents duplicate values in the indexed column. When inserting multiple rows in one query, if any row violates the unique constraint, the entire query fails and no rows are inserted.
🧠 Conceptual
intermediate1:30remaining
Why use a unique index instead of a primary key?
Which of the following is a valid reason to create a unique index on a column instead of making it a primary key?
Attempts:
2 left
💡 Hint
Think about the number of primary keys allowed per table.
✗ Incorrect
A table can have only one primary key but can have multiple unique indexes on different columns. Unique indexes enforce uniqueness but allow more flexibility than primary keys.
📝 Syntax
advanced1:30remaining
Which statement correctly creates a unique index?
Choose the correct SQL statement to create a unique index named
idx_unique_username on the username column of the accounts table.Attempts:
2 left
💡 Hint
Check the correct order of keywords in MySQL syntax for unique indexes.
✗ Incorrect
The correct syntax to create a unique index in MySQL is
CREATE UNIQUE INDEX index_name ON table_name (column);. Option C has wrong keyword order, C and D are invalid syntax for index creation.❓ optimization
advanced1:30remaining
How does a unique index improve query performance?
Which of the following best explains how a unique index can improve query speed?
Attempts:
2 left
💡 Hint
Think about how uniqueness helps the database find data faster.
✗ Incorrect
A unique index lets the database engine stop searching once it finds a matching value because duplicates cannot exist, speeding up lookups.
🔧 Debug
expert2:30remaining
Why does this unique index creation fail?
Given the table
employees with existing data, the following command fails. Why?
CREATE UNIQUE INDEX idx_unique_email ON employees (email);MySQL
Table employees has duplicate emails in the email column.
Attempts:
2 left
💡 Hint
Think about what data must look like before creating a unique index.
✗ Incorrect
A unique index requires all values in the indexed column to be unique. If duplicates exist, the index creation fails.