0
0
MySQLquery~5 mins

Unique indexes in MySQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AAutomatically creates a primary key
BFaster data retrieval only
CAllows duplicate values but sorts them
DNo duplicate values in the indexed column(s)
Which SQL command creates a unique index on the 'email' column of the 'users' table?
ACREATE UNIQUE INDEX idx_email ON users(email);
BCREATE INDEX idx_email ON users(email);
CALTER TABLE users ADD UNIQUE email;
DCREATE PRIMARY KEY ON users(email);
Can a unique index allow NULL values in MySQL?
AOnly one NULL is allowed
BNo, NULLs are not allowed
CYes, multiple NULLs are allowed
DNULLs are converted to empty strings
What error occurs if you insert a duplicate value into a unique indexed column?
ASyntax error
BDuplicate entry error
CTimeout error
DNo error, duplicates allowed
What is a composite unique index?
AA unique index on multiple columns combined
BA unique index on a single column
CAn index that is not unique
DA primary key index
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.