SQLMentor // glossary

Primary Key

A primary key is a column (or set of columns) that uniquely identifies every row in a table. It is automatically NOT NULL and UNIQUE, and a table can have only one.

The primary key is the row's identity — the value other tables reference to link to it. Because it must be unique and non-null, the database rejects any insert or update that would create a duplicate or leave it empty.

A primary key made of a single column is a simple key; one spanning several columns is a composite key. Most databases automatically create a unique index on the primary key, so lookups by it are fast.

Example

CREATE TABLE employees (
  employee_id  NUMBER PRIMARY KEY,
  first_name   VARCHAR2(50),
  last_name    VARCHAR2(50)
);