A primary key is the column, or set of columns, that uniquely identifies each row in a table. The database enforces two rules on it: every value must be unique, and no value may be NULL.
A table can have only one primary key, and the database creates an index on it automatically, so lookups by key are fast. Key values should also stay stable once assigned, because foreign keys point at them, but that is a design rule the database does not enforce.
A UNIQUE constraint also blocks duplicates, and a table can have several of them. Unlike a primary key, it accepts NULL. PostgreSQL and MySQL allow many NULL values in a unique column, while SQL Server allows only one.
CREATE TABLE employees (
emp_id INT PRIMARY KEY,
name VARCHAR(100) NOT NULL
);
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
The diagram below the answer is the concept . Jump to it ↓