- All Courses
- PostgreSQL for Application Developers
- Modelling Your Data
- Keys and relationships
Lesson 1.3
Keys and relationships
A surrogate key is stable and meaningless, which is exactly what you want for identity.
6mIntermediate15.3k students
Overview
Keys are how rows find each other
A surrogate key is stable and meaningless, which is exactly what you want for identity. Natural keys change — email addresses, order numbers, country codes — and a changing primary key propagates through every referencing row.
Foreign keys are cheap insurance. Without them, orphaned rows accumulate quietly and cleanup scripts become a permanent fixture.
Many-to-many needs a join table. Once it exists it usually wants its own columns anyway — when the relationship was created, by whom, in what role.
In this lesson you will:
- Choose between surrogate and natural keys
- Enforce referential integrity
- Model many-to-many with a join table
Resources
Notes are not saved yet — they clear when you leave this page.
Previous Lesson
Normalisation in practice
29m
JSONB and when to use it
5m