What is a unique constraint?

Answer

A UNIQUE constraint ensures that all values in a column (or combination of columns) are distinct — no two rows can have the same value. Unlike the primary key, a table can have multiple unique constraints, and unique constraint columns can contain NULL (most RDBMS treat multiple NULLs as not violating uniqueness). Create: ALTER TABLE users ADD CONSTRAINT uq_email UNIQUE (email). A unique constraint implicitly creates a unique index, providing fast lookups. Use cases: enforcing uniqueness on email addresses, usernames, product codes, or any natural identifier that isn't the primary key.