A database is an organised collection of persistent data. Persistent means it stays stored when the program closes or the computer is switched off.
A relational database is a database with multiple tables that are linked together (that reference each other).
The tables are linked by keys: a field in one table holds values of the primary key of another table.
A database with just one table is sometimes called a flat file. Putting everything in one table means the same details get typed again and again.
Splitting data into linked tables means each set of details (a customer’s name and phone number, say) is stored once. That cuts duplication and the mistakes it causes.
Examples: a shop’s customers and orders, a doctor’s surgery’s patients and appointments, a streaming service’s users and playlists.
Exam tipA relational database links tables, not databases. AQA’s 2022 and 2025 reports say many students wrote “several databases linked together” and got nothing. Use the word data, not “information”.
Database
An organised collection of persistent data.
Relational database
A database with multiple tables that are linked together (that reference each other).
Persistent
Kept after the program ends or the power goes off, because it is held in secondary storage.
3.7.1 Relational databases
Tables, records, fields and data types
A bike-hire shop keeps a Customer table. Each row is a record and each column is a field.
Table: a structured collection of data organised into records (rows) and fields (columns). The table above has 4 records and 4 fields.
Record: a single entry in a table. It holds all the data about one item, such as one customer.
Field: a single piece of data within a record, such as a first name. Every record has the same fields.
Field names have no spaces: FirstName, not First Name.
Data type: each field has one data type, which decides what values it can hold. Choose the most suitable one:
Integer for whole numbers (Hours, Stock); real for numbers with decimals (Price); string (text) for names and anything with letters, spaces or leading zeros (a phone number); Boolean for yes/no fields (Paid); date for dates (HireDate).
A database record and a programming record (a RECORD structure in code) are different ideas with the same name. Here, a record is one row of a table.
CustomerID
FirstName
LastName
Town
1
Priya
Shah
Ashford
2
Tom
Okafor
Dover
3
Ella
Novak
Ashford
4
Sam
Reid
Folkestone
Exam tipPhone numbers are strings, not integers: they start with 0, contain spaces and are never used in arithmetic. AQA’s 2024 report says students mixed up “field” with “variable”. A field belongs to a table.
Table
A structured collection of data organised into records (rows) and fields (columns).
Record
A single entry in a table, holding the data about one item.
Field
A single piece of data within a record, such as a first name.
Data type
What kind of value a field holds, such as integer, real, string, Boolean or date.
3.7.1 Relational databases
Primary keys and foreign keys
Keys let the database pick out one record and link tables together.
Primary key: a field that is unique for every record in a table. CustomerID identifies exactly one customer.
Names, towns and dates make poor primary keys because two records can share them. That’s why tables usually have an ID field.
Foreign key: a field in one table that is also a primary key in another table. Foreign keys are used to link one table to another.
In Hire, CustomerID is a foreign key. Hire 103 has CustomerID 1, so it belongs to Priya Shah.
A foreign key value can repeat: Priya has two hires, so 1 appears twice in Hire’s CustomerID column. A primary key value can’t repeat within its own table.
To find the primary key of a table, ask: which field is different in every record, now and in the future?
CustomerID is the primary key of Customer and a foreign key in Hire.
Exam tipForeign key was the weakest definition in AQA’s 2024 and 2025 reports. Learn both halves: a field in one table that is a primary key in another table, and it links the two tables. It isn’t a “physical key”.
Exam tipIn a table of results or bookings, the student’s or customer’s ID usually repeats, so it can’t be that table’s primary key. AQA’s 2025 report says many students chose it anyway.
Primary key
A field that is unique for every record in a table.
Foreign key
A field in one table that is also a primary key in another table, used to link one table to another.
3.7.1 Relational databases
Data redundancy and data inconsistency
Relational databases help to remove two problems that come from storing the same data more than once.
Data redundancy: the unnecessary duplication of data within a database. In one big table, a customer’s name and phone number are typed again for every hire.
Data inconsistency: the same piece of data is stored in various parts of the database, but the copies are not identical, so the data can’t be relied on. One copy of Priya’s number ends 101 and another ends 110: which is right?
Redundancy causes inconsistency: every extra copy is another chance for a typing mistake, or for one copy to be updated and the others missed.
The fix: split the data into linked tables. Customer details go in a Customer table, stored once. Each hire stores only the CustomerID (a foreign key).
Now a phone number is changed in one place, and every hire linked to that customer uses the new value.
Redundancy also wastes storage space, and a flat file can’t hold a customer until they’ve made a hire.
Storing Priya’s details once removes the duplicates and the mismatch.
Exam tipKeep the two apart. Redundancy = duplicated data. Inconsistency = copies that don’t match. AQA’s 2024 report says students explaining inconsistency often described redundancy or wrong data types instead.
Data redundancy
The unnecessary duplication of data within a database.
Data inconsistency
When the same data is stored in various parts of a database but the copies are not identical, so the data is unreliable.
Flat file
A database that keeps all its data in one table.
3.7.2 Structured query language (SQL)
SELECT, FROM and WHERE
SQL (structured query language) is used to retrieve, add, change and delete data in a relational database. A SELECT query retrieves data.
SELECT lists the fields to show, separated by commas. FROM names the table. WHERE gives the condition a record must meet.
Text values go in quotes: WHERE Town = 'Ashford'. Single or double quotes are both fine. Numbers don’t need quotes. Dates go in quotes too: WHERE HireDate = '2026-05-09'.
Comparison operators: =, <> (not equal), <, >, <=, >=. SQL uses a single= to compare.
Join conditions with AND (both must be true) or OR (either can be true). A range needs two conditions:
SELECT HireID, BikeType
FROM Hire
WHERE Hours >= 3 AND Hours <= 5
On the Hire table above this returns hires 101 (Road), 102 (Mountain) and 104 (Road).
With OR, write the field name again each time: WHERE BikeType = 'Road' OR BikeType = 'Electric', not BikeType = 'Road' OR 'Electric'.
SELECT * means every field. It is real SQL, but exam questions name the fields they want, and the mark needs those fields and no others.
Each clause answers one question about the data you want.
Worked exampleWrite a query to show the first and last names of customers who live in Ashford.
SELECT FirstName, LastNameonly the fields asked for
FROM Customerthe table that holds names and towns
WHERE Town = 'Ashford'text in quotes, one = sign
Priya Shah and Ella Novak
Worked exampleWhat does SELECT HireID FROM Hire WHERE BikeType = 'Electric' OR Hours > 4 return?
Electric: 103, 105first condition
Hours over 4: 102 (5), 105 (6)second condition; 4 itself isn’t over 4
OR: either is enough, and 105 appears onceeach record is checked once
102, 103 and 105 (101 and 104 meet neither condition)
Exam tipNever write == in SQL. AQA accepted it in 2022 only; it is now marked wrong. Use the field names exactly as printed in the table, with no spaces.
SQL
Structured query language: the language used to retrieve and change data in a relational database.
Query
A request to retrieve data from a database, written with SELECT.
3.7.2 Structured query language (SQL)
Sorting results with ORDER BY
ORDER BY goes at the end of a query and sorts the results by a field.
ASC sorts in ascending order: A to Z, smallest number first, earliest date first. If you leave ASC and DESC out, ascending is used.
DESC sorts in descending order: Z to A, largest first, latest date first.
SELECT FirstName, LastName
FROM Customer
ORDER BY LastName ASC
This gives Novak, Okafor, Reid, Shah.
You can sort by more than one field: ORDER BY Town ASC, LastName ASC sorts by town, then by last name within each town.
The order of clauses is fixed: SELECT, FROM, WHERE, then ORDER BY.
Read the question’s wording: “most recent first”, “highest first” and “Z to A” all mean DESC; “oldest date first”, “cheapest first” and “alphabetical” mean ASC.
Worked exampleShow the HireID and Hours of every road-bike hire, longest hire first.
SELECT HireID, Hours FROM Hirefields, then table
WHERE BikeType = 'Road'only road bikes
ORDER BY Hours DESClongest first = largest first
104 (4 hours), then 101 (3 hours)
Exam tipIt is ORDER BY (two words, no comma between them), not SORT BY or ORDER. Write the field name before ASC or DESC.
ASC
Ascending: A to Z, smallest first, earliest date first. The default.
DESC
Descending: Z to A, largest first, latest date first.
3.7.2 Structured query language (SQL)
Queries across two tables
When the fields you need are in two tables, the query must say how the tables link. Exam queries use no more than two tables.
Method 1, a join in WHERE: list both tables in FROM and match the primary key to the foreign key in WHERE.
SELECT FirstName, HireDate
FROM Customer, Hire
WHERE Customer.CustomerID = Hire.CustomerID
AND BikeType = 'Electric'
ORDER BY HireDate ASC
Method 2, INNER JOIN … ON: AQA credits this equally.
SELECT FirstName, HireDate
FROM Customer INNER JOIN Hire
ON Customer.CustomerID = Hire.CustomerID
WHERE BikeType = 'Electric'
ORDER BY HireDate ASC
Both return Priya, 2026-05-09 and Sam, 2026-05-16.
Table.Field: when the same field name is in both tables (the linking field), put the table name first with a dot: Customer.CustomerID. Table first, field second.
Table names in front of the other fields are allowed too (Customer.FirstName), as long as each is the right table.
Forgetting the join condition matches every customer with every hire, so the results are wrong.
Each hire is matched to its customer, then the WHERE condition filters the matches.
Worked exampleHow a 6-mark two-table query is usually marked (AQA’s A–F style). Task: last names of customers who hired a mountain bike, A to Z.
A: SELECT LastNamethe right field(s) and no others
B: FROM Customerone correct table
C: , Hirethe second table (or INNER JOIN Hire ON …)
D: WHERE Customer.CustomerID = Hire.CustomerIDone correct condition
E: AND BikeType = 'Mountain'all the conditions, joined with AND
F: ORDER BY LastName ASCthe right sort
Novak. A query with any error can score at most 5 out of 6
Exam tipAQA’s 2023 report saw CustomerID.Customer: the wrong way round. It is Table.Field. In 2025 a quarter of students scored 0 on the two-table query, often by writing no SQL keywords at all. Write SELECT and FROM lines even if you’re unsure of the rest: they carry marks.
Join
Combining records from two tables by matching a foreign key to a primary key.
INNER JOIN … ON
SQL that joins two tables, with the matching condition after ON.
3.7.2 Structured query language (SQL)
Adding records with INSERT INTO
INSERT INTO adds a new record to a table.
The form is INSERT INTO table (field1, field2, …) VALUES (value1, value2, …).
The values must be in the same order as the fields listed, with the same number of each.
Each value must suit its field’s data type: text and dates in quotes, numbers without (quotes round numbers are tolerated). A value of the wrong type, or in the wrong place, puts the wrong data in a field.
The keyword is VALUES, plural, even for one value.
The new record needs a primary key value that isn’t already used: inserting a second customer with ID 5 would be rejected.
Worked exampleAdd hire 106: customer 3 hires a road bike on 2026-05-23 for 2 hours.
INSERT INTO Hire (HireID, CustomerID, BikeType, HireDate, Hours)table, then every field in brackets
VALUES (106, 3, 'Road', '2026-05-23', 2)same order; text and the date in quotes
Hire now has 6 records
Exam tipAQA’s 2024 report says fewer than a quarter got INSERT and UPDATE right, often because values didn’t match the fields’ data types. Check each value against its field before moving on.
INSERT INTO
SQL that adds a new record: INSERT INTO table (fields) VALUES (values).
3.7.2 Structured query language (SQL)
Changing and removing records: UPDATE and DELETE
UPDATE changes data in existing records. DELETE removes whole records. Both use WHERE to say which records.
UPDATE: UPDATE table SET field1 = value1, field2 = value2 WHERE condition. Separate the changes with commas.
UPDATE Hire
SET BikeType = 'Mountain', Hours = 4
WHERE HireID = 103
Using the primary key in WHERE changes exactly one record. A condition that matches several records changes all of them: UPDATE Hire SET Hours = Hours + 1 WHERE BikeType = 'Road' adds an hour to both road-bike hires.
DELETE: DELETE FROM table WHERE condition. It removes the whole record, so no field names are listed.
DELETE FROM Hire
WHERE CustomerID = 1 AND BikeType = 'Electric'
This removes hire 103 only. Both conditions must be true, and when one condition alone would match the wrong records, you need both.
Without WHERE, every record is changed or deleted.DELETE FROM Hire empties the table. A good habit: test the WHERE condition with a SELECT first.
Deleting a record that doesn’t exist does nothing. It isn’t an error.
Worked exampleCustomer 2 moves to Folkestone. Write the SQL.
UPDATE Customerthe table to change (not SELECT or INSERT)
SET Town = 'Folkestone'field = new value
WHERE CustomerID = 2the primary key, so only one record changes
Tom Okafor’s town is now Folkestone
Exam tipAQA’s 2025 report says students started UPDATE questions with SELECT, GET or INSERT. Learn the three shapes by heart: INSERT INTO … VALUES, UPDATE … SET … WHERE, DELETE FROM … WHERE.
What isn’t on the courseCreating or deleting tables (CREATE, DROP), counting or totalling (COUNT, SUM, GROUP BY), LIKE, BETWEEN and queries inside queries aren’t needed. Use >= AND <= for a range.
UPDATE
SQL that changes data in existing records: UPDATE table SET field = value WHERE condition.
DELETE
SQL that removes whole records: DELETE FROM table WHERE condition.