Programming

What is a primary key in SQL?

Short answer

A primary key is a column (or set of columns) that uniquely identifies each row in a table, and cannot contain duplicate or NULL values.

Every table typically has one primary key, which the database uses to enforce that no two rows are identical and to quickly locate specific rows.

Key properties

Primary key vs. foreign key

A primary key uniquely identifies rows within its own table. A foreign key is a column in one table that references a primary key in another table, creating a relationship between the two — for example, an "orders" table might have a customer_id foreign key referencing the primary key of a "customers" table.

Last reviewed: September 2026