AQA GCSE Computer Science (8525), section 3.7.1 (Relational databases)
What is a database?
A database is an organised collection of data that is stored so it can be searched, sorted and updated easily.
Relational databases
A relational database stores data in several linked tables. The tables are connected by keys, so data is stored only once and linked rather than copied.
Key terms
| Term | Meaning |
|---|---|
| Table | stores data about one type of thing, in rows and columns (e.g. Pupil) |
| Record | one row: all the data about one item (one pupil) |
| Field | one column: one piece of information (e.g. surname) |
| Data type | the kind of data a field holds: text, integer, real, Boolean, date |
| Primary key | a field that uniquely identifies each record, so no two records have the same value (e.g. PupilID) |
| Foreign key | a field in one table that is the primary key of another table, creating a link between them |
Example
Pupil table
| PupilID (primary key) | Name | FormID (foreign key) |
|---|---|---|
| 1 | Aisha | 10A |
| 2 | Ben | 10B |
| 3 | Cara | 10A |
Form table
| FormID (primary key) | Tutor |
|---|---|
| 10A | Ms Patel |
| 10B | Mr Jones |
FormID in the Pupil table is a foreign key, linking each pupil to their form. The tutor's name is stored once in the Form table.
Why relational databases?
- No data redundancy: the same data is not stored repeatedly. If the tutor's name were in every pupil record, it would be repeated many times.
- No data inconsistency: if a tutor changes, it is changed in one place. Otherwise, some records might have the old and some the new name.
- Saves storage, and is easier to update and search.
Common mistake: mixing up a record (a row) and a field (a column). Also, a primary key must be unique for each record, so a name is not a good choice. A foreign key is the one that links to another table.
Exam tip: when explaining why use a relational database, give both reduced redundancy (data not repeated) and reduced inconsistency (it is only changed in one place).
Check yourself
What is a primary key?
A field that uniquely identifies each record in a table.
What is a foreign key?
A field in one table that is the primary key of another table, linking the two.
Give one benefit of a relational database.
It avoids storing the same data repeatedly, so there is less redundancy and inconsistency.