Primary keys and foreign keys are fundamental concepts in IB Computer Science databases, yet many students confuse their roles or describe them too vaguely. In IB exams, students are expected to explain what each key is, why it is needed, and how keys are used to link tables together.
Clear understanding of keys is essential for topics such as relational databases, normalisation, and SQL queries.
What Is a Primary Key?
A primary key is a field (or combination of fields) that uniquely identifies each record in a table.
Key characteristics of a primary key:
- It must be unique
- It must never be empty (null)
- It identifies one and only one record
For example:
- A student ID in a student table
- An order number in an orders table
Even if two records share similar data, their primary key values must always be different.
Why Primary Keys Are Important
Primary keys are essential because they:
- Prevent duplicate records
- Allow records to be identified accurately
- Enable efficient searching and indexing
- Support relationships between tables
Without a primary key, a database cannot reliably manage or reference individual records.
In IB terms, the primary key ensures data integrity.
What Is a Foreign Key?
A is a field in one table that .
