28 min read
Primary Keys
A primary key uniquely identifies each row. MemberID tells the two Sophie Walshes apart.
Names Are Not Enough
The River Path is overdue. Oliver Bennett reads the loan slip: “Sophie Walsh.” He picks up the phone.
Amelia Hart stops him. “Which Sophie Walsh? We have two.”
One lives in York. She joined in 2024. Her membership is MemberID 1. The other lives in London. She joined in 2022. Her membership is MemberID 8.
Oliver was a breath away from ringing London about a book that belongs to York.
Names are friendly. Names are not unique. If the computer stored only FullName, every loan, fine, and phone call could attach to the wrong person the moment the second Sophie Walsh joined.
Click the table name, a column heading, or any value. Each piece has a job.
What Is a Primary Key?
MemberID 1 is the member in York. MemberID 8 is the member in London. The overdue copy of The River Path belongs to one of those numbers, not to the letters S-o-p-h-i-e.
A primary key is the field that uniquely identifies one row in a table. In Members, the primary key is MemberID.
What a Primary Key Must Do
A primary key has a strict job:
- Unique — no two members share MemberID 1.
- Never empty — a row without an ID cannot be pointed at later.
- One per table — Members has MemberID. Books has BookID.
Names fail uniqueness the moment the second Sophie Walsh walks in. They also change. A primary key should survive that. The name stays an ordinary field. The number is the identity.
What the desk can rely on
| Looks human | Identifies the row |
|---|---|
| Sophie Walsh | MemberID 1 or MemberID 8 |
| The River Path | BookID 1 |
| York | Not an identifier — many members can share a city |
Practice
Swipe or use the arrows to move between questions.
1 / 3
More lessons in Database Fundamentals · Next: Choosing Primary Keys · Previous: Data Types
