What is the purpose of the UNIQUE constraint?
This question focuses on data integrity mechanisms within relational databases. It tests knowledge of enforcing distinct values.
Why Interviewers Ask This
Interviewers need to confirm you understand how to prevent duplicate data entry. Data integrity is critical for business logic, and this constraint is a primary tool for maintaining it. They also check if you know how it differs from a primary key.
How to Answer This Question
State clearly that the constraint ensures all values in a column or combination are distinct. Explain its role in preventing duplicates. Briefly contrast it with the PRIMARY KEY constraint regarding NULL values and multiplicity per table.
Key Points to Cover
- Ensures distinct values
- Prevents duplicate data
- Allows multiple NULLs
- Maintains data integrity
Sample Answer
The UNIQUE constraint ensures that all values in a column or a combination of columns are distinct across the entire table. This prevents duplicate entries and helps maintain high data integrity. Unlike a primary key, a unique constraint allows multiple NULL values and can be applied to multiple columns simultaneously.
Common Mistakes to Avoid
- Confusing it with PRIMARY KEY entirely
- Forgetting it allows NULLs
- Not mentioning composite uniqueness
Practice This Question with AI
Answer this question orally or via text and get instant AI-powered feedback on your response quality, structure, and delivery.
Related Interview Questions
What is the difference between LIKE and equals operators in SQL?
Easy
TCSWhat is the difference between UNION and UNION ALL?
Easy
Describe a PRIMARY KEY and how it differs from a UNIQUE key
Medium
What is ER model in the DBMS?
Medium
FlipkartWhat is Join and explain its types?
Medium
FlipkartWhat is the ER model in DBMS?
Easy
Flipkart