Databases, SQL & Normalisation

H446 · 1.3 Exchanging Data · A-Level Computer Science

Component 01

Relational Database Concepts

Relation (Table)

A two-dimensional structure of rows and columns representing an entity.

Tuple (Row)

A single record in the table — one instance of the entity.

Attribute (Column)

A property of the entity — all values in a column share the same domain.

Primary Key

Uniquely identifies each tuple. Cannot be null. No two rows have the same PK value.

Foreign Key

An attribute in one table that references the primary key in another — creates a link between tables.

Referential Integrity

Ensures every FK value matches an existing PK value — no orphan records.

Composite Key

A primary key made of two or more attributes — needed when no single attribute is unique.

DBMS

Software that manages the database — provides query processing, security, concurrency control, backup.

Normalisation — Removing Redundancy

Unnormalised Form (UNF): Repeating groups and multiple values in a single field. Data redundancy present.

OrderIDCustomerNameCustomerCityProducts (repeating)ProductPrice
1Alice SmithLondonLaptop, Mouse£800, £20
2Bob JonesLondonMonitor£300
3Alice SmithLondonKeyboard, Mouse£50, £20

Problems: Alice's city repeated; Mouse price repeated; no atomic values in Products column.

SQL — A-Level Queries

JOIN Example

SELECT Students.name, Courses.title
FROM Students
INNER JOIN Enrolments ON Students.id = Enrolments.student_id
INNER JOIN Courses ON Enrolments.course_id = Courses.id
WHERE Students.year = 12
ORDER BY Students.name ASC

Aggregate Functions

SELECT year, COUNT(*) AS total_students, AVG(score) AS avg_score
FROM Students
GROUP BY year
HAVING AVG(score) > 65
ORDER BY avg_score DESC

Data Manipulation

-- Insert
INSERT INTO Students (name, year, score) VALUES ('Priya Patel', 12, 87)

-- Update
UPDATE Students SET score = 92 WHERE name = 'Priya Patel'

-- Delete
DELETE FROM Students WHERE year = 13 AND score < 40

ACID Properties & Concurrency

Atomicity

All operations in a transaction succeed, or none do. No partial commits.

Consistency

A transaction brings the database from one valid state to another. Constraints are enforced.

Isolation

Concurrent transactions do not interfere with each other — each runs as if alone.

Durability

Once committed, changes persist even if the system crashes — written to permanent storage.

Lost Update Problem

Two transactions read the same record simultaneously. Both modify it based on the original value. The second write overwrites the first — one update is lost.

Solution: Record locking — lock the record when one transaction reads it, preventing others from accessing it until the first transaction commits (or rolls back).

Interactive SQL Builder

Build a query against the sample Students table (id, name, year, score). The query updates as you configure it.

idnameyearscore
1Alice1287
2Bob1155
3Chloe1292
4Dan1173
5Eve1361
SELECT * FROM Students