What is the purpose of the UNIQUE constraint in SQL?
This question checks knowledge of data integrity mechanisms and how to prevent duplicate entries in columns.
Why Interviewers Ask This
Data integrity is critical in any application. Interviewers ask this to see if you know how to enforce business rules at the database level to prevent invalid data states caused by duplicates.
How to Answer This Question
Explain that the constraint ensures all values in a column are distinct. Mention that it prevents duplicate entries and maintains data quality. Differentiate it briefly from PRIMARY KEY if relevant to show depth.
Key Points to Cover
- Enforces distinct values
- Prevents duplicates
- Maintains data integrity
- Allows NULLs (usually)
Sample Answer
The UNIQUE constraint ensures that all values in a column or combination of columns are distinct, preventing duplicate entries. This helps maintain data integrity by guaranteeing that no two records share the same value…
Common Mistakes to Avoid
- Confusing with PRIMARY KEY
- Ignoring NULL handling
- Not mentioning composite uniqueness
Sound confident on this question in 5 minutes
Answer once and get a 30-second AI critique of your structure, content, and delivery. First attempt is free — no signup needed.