Skip to content

Primary Key

Easy — everyone uses thisDatabase

ELI5 — The Vibe Check

A primary key is the unique ID that every row in a table must have. Like a social security number for your data — no two rows can have the same one. It is how the database knows exactly which row you mean when you say 'give me user 42'.

Real Talk

A primary key is a column or set of columns that uniquely identifies each row in a table. It enforces the UNIQUE and NOT NULL constraints automatically. Every table should have a primary key. Common types are auto-incrementing integers (SERIAL) and UUIDs.

Show Me The Code

CREATE TABLE orders (
  id SERIAL PRIMARY KEY,  -- auto-increments
  user_id INT NOT NULL,
  total DECIMAL(10,2)
);

When You'll Hear This

"Always include a primary key on every table." / "The id column is the primary key."

Made with passive-aggressive love by manoga.digital. Powered by Claude.