Keys: what makes a row that row
Step 1 of 110%
Concept · step 1 of 11
What a key is
A key is a column, or a set of columns, whose value identifies one row and no other. The primary key is the one a table is known by.
- A key never repeats. no two customers share an
id. - A key is never missing. a row with no
idcould not be told apart from anything. - Postgres enforces both for a `PRIMARY KEY`, and keeps a unique index behind it. the lightning bolt on the board.
CREATE TABLE customers (
id BIGINT PRIMARY KEY,
name TEXT NOT NULL
);Ada is customer 1 and Linus is customer 2, and nothing can ever make that ambiguous. Every other table that needs to point at a customer will point at this
PostgreSQL docs: CREATE TABLE, PRIMARY KEY and UNIQUE ↗id, which is why it has to be this strict.Starting Postgres in your browser
About 5 MB the first time, cached after that.
PostgreSQL running in your browser