Databases and SQL
Computer Science · GCSE · The School
The vocabulary
A TABLE holds data about one kind of thing. A RECORD (row) is one of them. A FIELD (column) is one property. A PRIMARY KEY is a field whose value is unique for every record — the thing that lets you say exactly which record you mean. Get these four words right and database questions become straightforward.
Asking questions in SQL
SELECT name, score FROM students WHERE score > 60 ORDER BY score DESC; — choose the columns, name the table, filter the rows, sort the result. Almost every query you meet at this level is those four parts. Read it aloud in that order and SQL stops looking like code and starts looking like a sentence.
Why split into related tables
One giant table repeats the same class name on every pupil row: waste, and worse, a chance to spell it differently in two places. Split into Students and Classes, link them by a key, and each fact is stored ONCE. Storing a fact once is the whole idea behind relational databases.
One big table holds every order with the customer's name and address repeated on each row. Alice has ordered six times, so her address is stored six times — and when she moves, five rows get updated and one does not. Split it: a CUSTOMER table with CustomerID as primary key and the address stored ONCE, and an ORDERS table holding CustomerID instead. `SELECT * FROM Orders WHERE CustomerID = 7` joins them back when you need it.