Which is true about a PRIMARY KEY vs a UNIQUE constraint?
Options
- Both of them allow multiple NULLs in the constrained column
- One primary key per table (NOT NULL); many UNIQUE constraints (Correct option)
- A UNIQUE constraint never creates an index in the table
- Primary keys must always be integers, never text or UUIDs
Answer
A table has one primary key (NOT NULL, unique); it can have many UNIQUE constraints, which usually allow NULLs
Why
The primary key is THE identifier of each row: unique and never NULL, and a table has only one.
A UNIQUE constraint just forbids duplicate values in a column (like email). You can have several, and they usually allow NULL.
Both create an index automatically. Primary keys can be integers, UUIDs or other types.
Remember
One primary key per table; many UNIQUE constraints allowed.