Recall & Review
beginner
What is a unique index in a database?
A unique index is a database feature that ensures all values in the indexed column(s) are different. It prevents duplicate entries in those columns.
Click to reveal answer
intermediate
How does a unique index differ from a primary key?
A primary key is a unique index that also uniquely identifies each row and cannot be NULL. A unique index allows unique values but can have NULLs unless specified otherwise.
Click to reveal answer
beginner
What happens if you try to insert a duplicate value into a column with a unique index?
The database will reject the insert and return an error because the unique index enforces uniqueness and does not allow duplicates.
Click to reveal answer
beginner
How do you create a unique index on a column in MySQL?
You use the SQL command: <br>
CREATE UNIQUE INDEX index_name ON table_name(column_name);Click to reveal answer
intermediate
Can a unique index be created on multiple columns? What does it enforce?
Yes, a unique index can cover multiple columns. It enforces that the combination of values across those columns is unique for every row.
Click to reveal answer
What does a unique index guarantee in a database table?
✗ Incorrect
A unique index ensures that no two rows have the same value in the indexed column(s).
Which SQL command creates a unique index on the 'email' column of the 'users' table?
✗ Incorrect
The correct syntax to create a unique index is CREATE UNIQUE INDEX with the index name and table.column.
Can a unique index allow NULL values in MySQL?
✗ Incorrect
In MySQL, unique indexes allow multiple NULL values because NULL is not considered equal to another NULL.
What error occurs if you insert a duplicate value into a unique indexed column?
✗ Incorrect
The database returns a duplicate entry error to prevent violating the unique index constraint.
What is a composite unique index?
✗ Incorrect
A composite unique index ensures the combination of values across multiple columns is unique.
Explain what a unique index is and why it is useful in a database.
Think about how unique indexes help keep data clean and organized.
You got /3 concepts.
Describe how to create a unique index in MySQL and what happens if you try to insert duplicate data.
Recall the SQL command and the database behavior on duplicates.
You got /3 concepts.