The moment databases start to make sense (and your marks go up)
In IB Computer Science, database questions often feel easy until you try to explain them under exam pressure. You know a key “links tables”… but the wording slips, the definitions blur, and suddenly you’re writing something like: “a primary key is an important field.”
The problem isn’t your intelligence. It’s that databases reward precision. Primary keys and foreign keys are simple ideas, but they sit underneath normalisation, referential integrity, and SQL joins. When you get them right, a lot of the topic becomes calmer.
If you want a syllabus-aligned home base while you revise, keep the IB Computer Science A. Databases hub open as you go.

Quick checklist for IB Computer Science exam answers
Use this mini-checklist before you write anything about keys in IB Computer Science:
-
Define primary key: unique identifier for each record (row)
-
State rules: unique and not null
-
Define foreign key: field that references a primary key in another table
-
Say what keys achieve: link tables and protect data integrity
-
Add a short example (StudentID, OrderID, etc.)
For broader database revision structure, see The Best Way to Revise Databases for IB Computer Science.
What is a primary key in IB Computer Science?
A primary key is a field (or combination of fields) that uniquely identifies each record in a table.
In IB Computer Science, the examiner usually wants you to mention three properties:
-
Unique: no two rows share the same primary key value
-
Not null: every row must have a value (no blanks)
-
One per record: it points to exactly one specific row
Examples that score well:
-
StudentIDin a Students table -
BookIDin a Books table -
OrderNumberin an Orders table
If you’re mixing this up with general “important attributes,” anchor your terminology with the notes on Designing Relational Databases.
Why primary keys matter (beyond definitions)
A database without a primary key is like a school register without student numbers. You can still write names, but the first time you have two students called “Alex Chen,” everything becomes guesswork.
Primary keys matter in IB Computer Science because they:
-
prevent duplicate records from quietly appearing
-
make updates safer (you target the correct row)
-
make searching/indexing efficient
-
provide the “anchor point” for relationships between tables
This is also where the phrase data integrity belongs. If you want a clean exam-ready contrast of integrity vs consistency, read Data Integrity and Consistency Explained.
What is a foreign key in IB Computer Science?
A foreign key is a field in one table that references the primary key of another table.
Think of it as a controlled “pointer” between tables. In IB Computer Science, you should state that foreign keys:
-
create links between entities (tables)
-
enforce referential integrity (no invalid references)
-
reduce duplication by storing a value once and referencing it elsewhere
Example:
-
Students table has
StudentIDas the primary key -
Enrollments table includes
StudentIDas a foreign key to show which student enrolled
To deepen the mark-scheme language around invalid references, use Referential Integrity notes.

How primary keys and foreign keys work together
Here’s the high-scoring explanation:
-
A primary key uniquely identifies a record in its own table.
-
A foreign key stores that primary key value in a different table to create a relationship.
This is the backbone of relational databases, and it directly supports normalisation. Instead of repeating a student’s name in every table, you store it once, then reference the student via StudentID. If you want the “why” behind splitting tables, see Normalisation Explained for IB Computer Science.
When you move into SQL, keys become the reason joins work. A join is basically the database saying: “match these IDs.” For that next step, read Joins Explained: Combining Data from Multiple Tables.
Common IB Computer Science mistakes (and how to fix them)
-
Vague definitions: “important field” doesn’t earn much. Say “uniquely identifies each record” and add unique/not null.
-
Swapping roles: primary key identifies; foreign key references.
-
Ignoring nulls: primary keys cannot be null; foreign keys sometimes can be null depending on optional relationships.
-
Forgetting integrity: mention referential integrity when explaining why foreign keys matter.

Final takeaway (and how RevisionDojo helps)
In IB Computer Science, primary keys uniquely identify records, while foreign keys reference those primary keys to link tables reliably. Get those two sentences exam-ready, and topics like normalisation and joins stop feeling like separate chapters and start feeling like one connected system.
When you’re ready to lock it in, RevisionDojo makes the practice loop simple: targeted Study Notes, rapid Flashcards, an exam-style Questionbank, plus AI Chat and Grading tools to tighten your explanations. Add Mock Exams, Predicted Papers, a Coursework Library, and Tutors when you want full exam preparation support in one place.