Primary Keys · Cambridge syllabus 9.3 · Lesson 1 of 1
Primary Key
A primary key uniquely identifies a record and must not be duplicated or missing. A name may be unsuitable because different records can share it. A stable dedicated identifier is often clearer.
By the end, you can
- Understand the purpose of a primary key.
- Identify a suitable primary key for a table.
- Explain why a primary key must uniquely identify records.
Identifying records
A primary key is a field whose value identifies each record uniquely. No two records may share it, and it may never be empty.
It exists because records must be told apart with certainty. Two pupils can share a name, a date of birth and a class; a search on any of those may return several records, and updating the wrong one corrupts the data silently. A key that is unique by rule removes the ambiguity.
A good key is unique, never changes, and is always present. Choosing a natural field means checking those three properties honestly: an email address is unique but can change; a name is neither unique nor unchanging; a national identifier may be unique but is not held for everyone and is sensitive to store.
That is why most tables use a field created for the purpose — PupilID, BookID, OrderNumber — generated automatically and never reused or edited. It carries no meaning, which is exactly its virtue: a value with no meaning has no reason to change.
The database enforces the rule rather than trusting anyone to follow it: an attempt to insert a duplicate key, or to leave it blank, is rejected. The key is also what another table refers to when relating records to one another, which is where relational databases begin.
Worth remembering
- A primary key uniquely identifies a record and can never be blank.
- A good key is unique, unchanging and always present.
- A generated identifier is usual, because a value with no meaning never needs to change.
Worked example
Two students can both be named Sam, so a unique StudentID is more reliable as a primary key.
Practice
Warm-up · not marked
Check your understanding
Answer in your own words, then compare with the worked answer. Nothing here is saved or scored.
Worked answer
Many people can share an age and it changes over time, so it does not uniquely and stably identify a record.
Check your method, units and explanation against it.
Marked practice
Set 1 of 4 · easiest first · Checked as you go, with the worked answer. Sign in or create a free account to save your progress.