0
0
SQLquery~5 mins

UNIQUE constraint in SQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the UNIQUE constraint in SQL?
The UNIQUE constraint ensures that all values in a column or a group of columns are different from each other, preventing duplicate entries.
Click to reveal answer
beginner
Can a table have multiple UNIQUE constraints?
Yes, a table can have multiple UNIQUE constraints on different columns or sets of columns to enforce uniqueness in multiple ways.
Click to reveal answer
intermediate
How does UNIQUE constraint differ from PRIMARY KEY?
PRIMARY KEY uniquely identifies each row and does not allow NULLs. UNIQUE constraint also enforces uniqueness but allows NULL values (depending on the database).
Click to reveal answer
beginner
Write a SQL statement to add a UNIQUE constraint on the 'email' column of a table named 'users'.
ALTER TABLE users ADD CONSTRAINT unique_email UNIQUE (email);
Click to reveal answer
beginner
What happens if you try to insert a duplicate value into a column with a UNIQUE constraint?
The database will reject the insert or update operation and return an error because it violates the UNIQUE constraint.
Click to reveal answer
What does the UNIQUE constraint do in a SQL table?
AAllows duplicate values in a column
BPrevents duplicate values in a column
CDeletes duplicate rows automatically
DCreates an index without enforcing uniqueness
Can a UNIQUE constraint column contain NULL values?
ANo, NULLs are not allowed
BYes, usually NULLs are allowed and can appear multiple times
CYes, but only one NULL is allowed
DIt depends on the database system
Which SQL command adds a UNIQUE constraint to an existing table?
AALTER TABLE ... ADD UNIQUE
BCREATE UNIQUE CONSTRAINT
CINSERT UNIQUE INTO
DUPDATE TABLE ... SET UNIQUE
How many UNIQUE constraints can a table have?
AOnly one
BTwo
CMultiple
DNone
What error occurs if you insert a duplicate value into a UNIQUE column?
AConstraint violation error
BSyntax error
CNo error, duplicates allowed
DConnection error
Explain what the UNIQUE constraint does and how it differs from a PRIMARY KEY.
Think about uniqueness and NULL values.
You got /4 concepts.
    Describe how to add a UNIQUE constraint to an existing table and what happens if a duplicate value is inserted.
    Consider the SQL command and error behavior.
    You got /3 concepts.