Interview Question

What is a unique key?

UNIQUE prevents duplicate constrained values; PRIMARY KEY is the main row identifier.

💡 Concept ✅ Quick Revision 🗃️ SQL

Answer

A UNIQUE constraint requires the constrained values to be distinct according to the database null rules. • A table can have several UNIQUE constraints. • A UNIQUE constraint can cover one or multiple columns. • Use PRIMARY KEY for the chosen main row identifier.

💡 SQL Example

CREATE TABLE users (user_id integer PRIMARY KEY, email text UNIQUE);

Result

CREATE TABLE

⚡ Quick Revision

UNIQUE prevents duplicate constrained values; PRIMARY KEY is the main row identifier.