EuraStudy
Databases store the structured data that most software depends on, and this chapter develops how they are modelled, designed and queried. It covers entity relationship modelling and the relational model, normalisation to third normal form to remove redundancy, the SQL used to query and modify data, referential integrity, and the transaction processing and ACID properties that keep a shared database correct under concurrent access.
5 sections~17 min reading time3 competenciesLevel Standard 3 · Advanced 2
basic level
AS-Level expects the relational model, primary and foreign keys, and simple SQL SELECT queries.
higher level
The full A-Level adds entity relationship modelling, normalisation to 3NF, multi-table SQL with JOINs and data modification, referential integrity, and transaction processing with ACID.
Reading depth: In depth
Text size: Standard
An entity relationship model with a link entity
A school records which students study which subjects: each student studies several subjects and each subject is studied by several students. Design the tables.
Student to Subject is many-to-many, which cannot be stored directly in relational tables.
Create a StudentSubject link table holding StudentID and SubjectID as foreign keys (together a composite primary key), plus any pairing attributes such as the set or grade.
Student(StudentID, Name, ...), Subject(SubjectID, Title, ...), and StudentSubject(StudentID, SubjectID, ...) - two one-to-many relationships replacing the many-to-many.
Result: Three tables: Student, Subject and the StudentSubject link table. Each row of the link table records one student studying one subject, so the many-to-many is fully represented.
Typical mistakes
Active revision
A library lends books to members; a member can borrow many books over time and each copy of a book can be borrowed by many members. Identify the entities and relationships, state the degree of each, and explain how you would resolve any many-to-many relationship.
Active recall
Recall the key points — then reveal.
Sources: GCE AS and A level subject content for computer science (Department for Education) · AQA A-level Computer Science 7517 specification (AQA)
The first three normal forms
An order table repeats, for each order: OrderID, CustomerName, CustomerAddress, and a list of (ProductID, ProductName, Quantity). Normalise it to 3NF.
Remove the repeating group of products: one row per product line. Table (OrderID, CustomerName, CustomerAddress, ProductID, ProductName, Quantity) with composite key (OrderID, ProductID).
Remove partial dependencies on part of the key: CustomerName/Address depend on OrderID only, ProductName on ProductID only. Split into Orders(OrderID, CustomerName, CustomerAddress), Product(ProductID, ProductName) and OrderLine(OrderID, ProductID, Quantity).
Remove the transitive dependency: CustomerName/Address depend on the customer, not the order. Split into Customer(CustomerID, Name, Address) and Orders(OrderID, CustomerID).
Result: Four 3NF tables: Customer(CustomerID, Name, Address), Orders(OrderID, CustomerID), Product(ProductID, ProductName), OrderLine(OrderID, ProductID, Quantity). Each fact is stored once and tables are linked by foreign keys.
Typical mistakes
Active revision
An unnormalised booking table stores, per booking: BookingID, MemberName, MemberPhone, and for each session booked (SessionID, SessionTitle, Date). Normalise it to 3NF, showing the tables and their keys at each stage.
Active recall
Recall the key points — then reveal.
Sources: AQA A-level Computer Science 7517 specification (AQA)
A sample Student table
From the Student table (StudentID, Name, Mark) with rows Adeyemi 72, Brookes 38, Chen 55, Diaz 81, write SQL to list the names and marks of students who passed (mark 40 or more), highest first, and give the result.
SELECT Name, Mark FROM Student - the required columns from the Student table.
Add WHERE Mark >= 40 to keep only passes, and ORDER BY Mark DESC to sort from highest to lowest. Full query: SELECT Name, Mark FROM Student WHERE Mark >= 40 ORDER BY Mark DESC;
Brookes (38) fails the WHERE test and is dropped; the rest sort as Diaz 81, Adeyemi 72, Chen 55.
Result: The query returns three rows: Diaz 81, Adeyemi 72, Chen 55. The WHERE clause filtered the rows and ORDER BY ... DESC sorted them.
Typical mistakes
Active revision
Using the Student table (StudentID, Name, Mark) opposite, write SQL to list the Name and Mark of every student scoring at least 40, sorted from highest to lowest mark, and separately write SQL to return the average mark of all students.
Active recall
Recall the key points — then reveal.
Sources: AQA A-level Computer Science 7517 specification (AQA)
Write SQL to (a) add a student S5 named Evans with mark 64, and (b) raise the mark of student S2 to 45. Explain the role of the WHERE clause in (b).
INSERT INTO Student (StudentID, Name, Mark) VALUES ('S5', 'Evans', 64); - text values are quoted, the numeric mark is not.
UPDATE Student SET Mark = 45 WHERE StudentID = 'S2'; - the WHERE clause restricts the change to the one intended row.
Without WHERE, UPDATE Student SET Mark = 45 would set every student's mark to 45 - the WHERE clause is what limits the update to S2.
Result: The INSERT adds Evans; the UPDATE changes only S2's mark to 45. The WHERE clause is essential to avoid altering every row.
Typical mistakes
Active revision
Write SQL to insert a new student (S5, 'Evans', 64) into the Student table, then to increase every mark below 40 by 5, and finally explain what referential integrity would do if you tried to delete a Course that still has enrolments referring to it.
Active recall
Recall the key points — then reveal.
Sources: AQA A-level Computer Science 7517 specification (AQA)
The ACID properties of a transaction
Two transactions both read an account balance of 200 and each subtract 50. Explain how the balance could wrongly end at 150, and how locking fixes it.
Transaction A reads 200; before it writes, transaction B also reads 200. A writes ; B, still holding its stale 200, writes , overwriting A. One withdrawal is lost - the balance is 150, not 100.
When A starts, it locks the balance record. B must wait until A commits and releases the lock.
B now reads the updated 150 and writes . The transactions effectively ran one after the other (isolation), giving the correct result.
Result: With record locking the final balance is 100, not 150. Locking enforces isolation so concurrent transactions cannot overwrite each other's updates - the lost update is prevented.
Typical mistakes
Active revision
Two cashpoints simultaneously read an account balance of 200 and each withdraw 50. Explain how a lost update could leave the balance at 150 instead of 100, and how record locking and the ACID properties prevent it.
Active recall
Recall the key points — then reveal.
Sources: AQA A-level Computer Science 7517 specification (AQA)
References & sources
Department for Education