What is the purpose of the UNIQUE constraint?

SQL
Easy
87.9K views

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.

Start Practicing

Related Interview Questions

Browse all 49 SQL questions