AQA 7517, section 4.10.2
The concept of a relational database
A relational database stores data in several linked tables (called relations). Each table holds data about one type of thing, and the tables are linked together by shared values called keys.
Instead of storing everything in one big table (a flat file), the data is split up, so that each fact is stored only once.
Problems with a single flat file
Imagine one table for a school library:
| LoanID | StudentName | TutorGroup | BookTitle | Author | DateBorrowed |
|---|---|---|---|---|---|
| 1 | Asha Khan | 12A | Dune | F. Herbert | 2026-11-02 |
| 2 | Asha Khan | 12A | Emma | J. Austen | 2026-11-09 |
| 3 | Ben Ortiz | 12B | Dune | F. Herbert | 2026-11-10 |
- Data is repeated: Asha's name and group appear twice, and the details of Dune appear twice (redundancy).
- If Asha changes tutor group, every row must be updated, or the data becomes inconsistent.
- It wastes storage.
The relational solution
Split it into three tables, linked by keys:
STUDENT
| StudentID | Name | TutorGroup |
|---|---|---|
| 1 | Asha Khan | 12A |
| 2 | Ben Ortiz | 12B |
BOOK
| ISBN | Title | Author |
|---|---|---|
| 978-0-441 | Dune | F. Herbert |
| 978-0-141 | Emma | J. Austen |
LOAN
| StudentID | ISBN | DateBorrowed |
|---|---|---|
| 1 | 978-0-441 | 2026-11-02 |
| 1 | 978-0-141 | 2026-11-09 |
| 2 | 978-0-441 | 2026-11-10 |
Each fact is now stored once. Asha's group can be changed in one place. The tables are linked by the StudentID and ISBN values.
Terminology
| Term | Meaning |
|---|---|
| Table (relation) | A set of data about one type of entity, laid out in rows and columns |
| Record (row, tuple) | One instance: for example, one student |
| Attribute (field, column) | One property of the entity: for example, Name. Each has a data type |
| Primary key | An attribute that uniquely identifies each record in a table |
| Composite primary key | A primary key made of two or more attributes combined |
| Foreign key | An attribute in one table that is the primary key of another table, used to link the two |
Attribute
An attribute is a column in a table: one piece of information held about each record, such as Name or TutorGroup.
Primary key
A primary key is an attribute whose value is unique for every record, so it can identify exactly one record. It can't be empty (null), and should never change.
- In
STUDENT,StudentIDis the primary key. Two students could have the same name, so a name is not a good key. - A meaningless ID number is often added to be the key.
Composite primary key
Sometimes no single attribute is unique, but a combination is. A composite primary key is made of two or more attributes.
In LOAN, the same student can borrow many books, and the same book can be borrowed by many students. So neither StudentID nor ISBN is unique on its own. Together with the date, (StudentID, ISBN, DateBorrowed) identifies a loan, so it is a composite key. (A table with just StudentID and ISBN would have a composite key of those two, if each pair could only appear once.)
Foreign key
A foreign key is an attribute in one table that refers to the primary key of another table. It is how tables are linked.
- In
LOAN,StudentIDis a foreign key, linking to the primary key ofSTUDENT. - In
LOAN,ISBNis a foreign key, linking to the primary key ofBOOK.
A foreign key must match an existing value in the table it refers to. You can't record a loan for a student who doesn't exist. This rule is called referential integrity. The database refuses to add or delete data that would break the link.
How the tables are linked: relationships
- A one-to-many relationship is built by putting the primary key of the "one" side into the "many" table as a foreign key. For example,
TutorGroupcould be its own table, and eachSTUDENTwould hold a foreign key to it. - A many-to-many relationship is built with a linking table, like
LOAN, holding the foreign keys of both sides.
Advantages of a relational database
- Reduced redundancy: each fact is stored once, saving space.
- Consistency: a change is made in one place.
- Integrity: keys and rules stop invalid data.
- Flexible queries: the data can be combined in many ways using SQL (4.10.4).
- Data is easier to maintain and update.
Worked example
Task: a database has these two tables. Identify the primary keys and the foreign key.
EMPLOYEE (EmployeeID, Name, DepartmentID)
DEPARTMENT (DepartmentID, DepartmentName)
EmployeeIDis the primary key ofEMPLOYEE, andDepartmentIDis the primary key ofDEPARTMENT.DepartmentIDinEMPLOYEEis a foreign key, because it refers to the primary key ofDEPARTMENT. It links each employee to their department.- An employee can't be assigned a department that doesn't exist in
DEPARTMENT(referential integrity).
Exam tip: define the key terms precisely. A primary key uniquely identifies a record, a composite key uses more than one attribute, and a foreign key is an attribute that is the primary key of another table, used to link tables. Always say which table a foreign key refers to.
Check yourself
What is a relational database?
A database that stores data in several linked tables, each about one type of entity, with the tables linked by keys so that each fact is stored only once.
What is a primary key?
An attribute (or set of attributes) whose value is unique for every record in the table, so it identifies exactly one record.
What is a composite primary key?
A primary key made up of two or more attributes combined, used when no single attribute is unique on its own.
What is a foreign key?
An attribute in one table that is the primary key of another table, used to link the two tables.
Why is a student's name a poor choice of primary key?
Two students could have the same name, so it wouldn't be guaranteed to be unique, and names can also change.