โ† Back to subjects
โญ 0
AQA A-level Computer Science (7517) ยท Fundamentals of databases
Mini-Lesson

Fundamentals of databases

This mini-lesson covers AQA 4.10 โ€” Fundamentals of databases: how to model data properly, normalise it to third normal form, query it in SQL, and keep it correct when thousands of users hit it at once.

  • Entity relationship modelling
  • Primary, foreign and composite keys; referential integrity
  • Normalisation โ€” 1NF, 2NF, 3NF
  • SQL โ€” SELECT, INSERT, UPDATE, DELETE and JOIN
  • Transactions, ACID and record locking

Work through each screen, answer the questions as you go (some are recall, some are calculations you must actually work out) and collect โญ stars. Press Start when you're ready.

4.10 ยท Modelling

Entity relationship modelling

An entity is a thing you store data about (Student, Course, Order). An attribute is a property of it. A relationship links entities, and its degree matters enormously:

  • One-to-one โ€” each person has one passport. Rare; often the two entities should just be merged.
  • One-to-many โ€” one tutor has many students. The commonest case: put the foreign key on the "many" side.
  • Many-to-many โ€” a student takes many courses, and a course has many students. A relational database cannot store this directly.

A many-to-many is resolved with a link table (junction table), which turns it into two one-to-many relationships:

Student(StudentID, Name) Course(CourseID, Title) Enrolment(StudentID, CourseID, Grade) // composite primary key

The pay-off: the link table is also the natural home for attributes belonging to the relationship itself โ€” a grade belongs neither to the student alone nor the course alone, but to the pairing.

Calculate

Your turn โ€” resolving many-to-many

1A many-to-many relationship between Student and Course is resolved with a link table. How many attributes make up the composite primary key of that link table?
attributes
Hint: The link table must uniquely identify each pairing, so its key is made from the primary key of each side.
4.10 ยท Keys

Keys and referential integrity

  • Primary key โ€” the attribute (or set of attributes) that uniquely identifies each record. It can never be null or duplicated.
  • Composite key โ€” a primary key made of two or more attributes together.
  • Foreign key โ€” an attribute in one table that refers to the primary key of another. This is what joins tables.
  • Secondary key / index โ€” an extra index to speed up common searches.

Referential integrity is the rule that every foreign key value must match an existing primary key โ€” or be null. The DBMS enforces it, so you cannot:

  • add an order for a customer who does not exist;
  • delete a customer who still has orders (leaving orphan records pointing at nothing).

Why it matters: without referential integrity, a database rots quietly. Orphan records accumulate, reports silently under-count, and the errors are almost impossible to trace back. The constraint is not bureaucracy โ€” it is the database refusing to let you lie to it.

4.10 ยท Normalisation

Normalisation โ€” 1NF, 2NF, 3NF

Normalisation restructures tables to remove redundancy and the update, insert and delete anomalies it causes.

FormRuleFixes
1NFAtomic values only โ€” no repeating groups, no lists in a cell. Every record identifiable."Subjects: Maths, Physics" in one cell
2NFIn 1NF and every non-key attribute depends on the whole primary key, not part of it.Partial dependency (only ever an issue with a composite key)
3NFIn 2NF and no non-key attribute depends on another non-key attribute.Transitive dependency

The exam mantra: every non-key attribute depends on the key, the whole key, and nothing but the key.

A 3NF violation you can see

Student(StudentID, Name, TutorID, TutorName)

TutorName depends on TutorID, which is not the key. So change one tutor's name and you must edit every row for their students โ€” miss one and the database now holds two contradictory names for the same person.

Fix: split into Student(StudentID, Name, TutorID) and Tutor(TutorID, TutorName).

The honest trade-off: a fully normalised database needs more joins to answer a query, which costs time. Data warehouses are often deliberately denormalised for read speed โ€” but you only break the rule once you can explain exactly why.

Quick check

Normalisation

?A table OrderLine(OrderID, ProductID, Quantity, ProductName) has the composite primary key (OrderID, ProductID). Which normal form does it violate, and why?
4.10 ยท SQL

SQL โ€” querying and updating

SELECT Name, Grade FROM Student WHERE Grade >= 60 AND YearGroup = 13 ORDER BY Grade DESC; INSERT INTO Student (StudentID, Name, TutorID) VALUES (105, 'Ada Lovelace', 3); UPDATE Student SET TutorID = 4 WHERE StudentID = 105; DELETE FROM Student WHERE StudentID = 105;

An INNER JOIN combines rows from two tables wherever the foreign key matches the primary key:

SELECT Student.Name, Tutor.TutorName FROM Student INNER JOIN Tutor ON Student.TutorID = Tutor.TutorID WHERE Tutor.TutorName = 'Hopper';

Aggregates work with GROUP BY: COUNT, SUM, AVG, MIN, MAX.

The most dangerous line in SQL: DELETE FROM Student; โ€” with the WHERE clause forgotten, that deletes every row in the table. The same is true of UPDATE. Always write the WHERE clause first.

Calculate

Your turn โ€” count the query results

2The Orders table holds these Total values: 20, 55, 60, 45, 100, 50.
SELECT COUNT(*) FROM Orders WHERE Total > 50;
What does the query return?
Hint: Strictly greater than 50 โ€” so 50 itself does not qualify.
Calculate

Your turn โ€” the join

3Student: (S1, Ada, T1) (S2, Alan, T2) (S3, Grace, T1) (S4, Linus, T3)
Tutor: (T1, Hopper) (T2, Turing) (T3, Knuth)
SELECT Student.Name FROM Student INNER JOIN Tutor ON Student.TutorID = Tutor.TutorID WHERE Tutor.TutorName = 'Hopper';
How many rows does this return?
rows
Hint: Which tutor ID belongs to Hopper? Now count the students carrying that foreign key.
4.10 ยท Transactions

Transactions, ACID and concurrency

A transaction is a group of operations that must succeed or fail as one indivisible unit โ€” a bank transfer is a debit and a credit. The ACID properties guarantee it:

PropertyGuarantee
AtomicityAll of it happens, or none of it does. A failure halfway triggers a rollback.
ConsistencyThe database moves from one valid state to another; all constraints still hold.
IsolationConcurrent transactions do not interfere; the result is as if they ran one after another.
DurabilityOnce committed, the change survives a power cut or crash โ€” it is written to non-volatile storage.

Concurrency control: if two users update the same record at once, one update can silently overwrite the other โ€” the lost update problem.

  • Record locking โ€” lock the record while it is being updated. Risk: deadlock, where A holds a lock B wants and B holds a lock A wants, and both wait forever.
  • Serialisation โ€” force transactions to run one at a time on the contested data.
  • Timestamp ordering โ€” each transaction is stamped; conflicts are resolved by age, and an offending transaction is rolled back and restarted.
  • Commitment ordering โ€” commits are ordered to preserve serialisability without deadlock.
Quick check

ACID

?Halfway through a bank transfer, the server loses power: ยฃ100 has been debited from account A but not yet credited to account B. Which ACID property ensures the ยฃ100 does not simply vanish?
Quick check

Referential integrity

?A DBMS refuses to delete a customer record because that customer still has orders in the Order table. What is being enforced?
Sort it

Which normal form is broken?

Tap the flaw, then tap the normal form it violates.

1๏ธโƒฃ Breaks 1NF

2๏ธโƒฃ Breaks 2NF

3๏ธโƒฃ Breaks 3NF

Match it

Match the SQL statement to its job

Tap an item on the left, then its partner on the right.

Job
SQL
Recap

The big ideas to know

ER modelling: one-to-one ยท one-to-many (foreign key on the many side) ยท many-to-many โ†’ link table with a composite key

Keys: primary (unique, never null) ยท foreign (points at a primary key) ยท referential integrity blocks orphans

Normalisation: 1NF atomic ยท 2NF no partial dependency ยท 3NF no transitive dependency โ€” the key, the whole key, nothing but the key

SQL: SELECT/FROM/WHERE/ORDER BY/GROUP BY ยท INNER JOIN on FK = PK ยท INSERT ยท UPDATE ยท DELETE (never forget WHERE)

Transactions: ACID: atomicity ยท consistency ยท isolation ยท durability

Concurrency: record locking (beware deadlock) ยท serialisation ยท timestamp ordering ยท commitment ordering

That is the whole of AQA 4.10. Press Finish to see your score.

๐Ÿ†

Mini-lesson complete!

โญโญโญ

You've worked through Fundamentals of databases for AQA A-level Computer Science (7517). ๐ŸŽ‰

Your stars: 0 / 0

Next: test yourself in the Evaluate stage Confidence Quiz, then lock it in with Verify.

๐Ÿ“ฃ Smashed it? Share your score

Challenge a mate to beat your stars, or show a parent how you got on.

โ†’ Back to all subjects