Databases & SQL

💻 Computer Science Years 10–11 Foundation

Organising data in database tables of records and fields, and using SQL (SELECT, FROM, WHERE, INSERT) to query and add data.

Open this lesson, with practice and a printable worksheet →

A comma-separated file is fine for a few hundred rows. But how does a school hold thousands of pupils, or a shop track every order, and still answer “who scored over 70?” in a blink? They use a database — data organised into tables — and a language built to question it: SQL.

Why this matters: Almost every app you use — banking, streaming, shopping — sits on a database. SQL (Structured Query Language) is how programs and people ask a database questions and change its data. It appears in exams because it tests table structure, logic and precise conditions all at once.
ID Name Mark 1Aisha72 2Omar64 3Leah88 ← a record
A table: columns are fields, each row is one record; the dashed box is the Name field.

Tables, records and fields

IDName1Sara2Sara3Omarprimary key← same name,different ID
The primary key (ID) is unique, so identical names are never confused.

A database table is a grid, like a spreadsheet. Each column is a field (one kind of data, e.g. Name). Each row is a record (all the data about one pupil). One field is usually a primary key — a unique value like an ID that no two records share, so every record can be told apart even if two pupils happen to have the same name. Without a primary key, the database could not reliably pick out one exact record.

SELECT: asking questions

SELECTFROMWHEREwhich fields?which table?which rows?NamePupilsMark > 70the order is always SELECT … FROM … WHERE
Read a query in three parts: fields, table, then the filter.

The most-used SQL command is SELECT. It answers “show me…”. You name the fields you want, the table they live in, and an optional WHERE condition to filter. Think of it as a highly literal librarian: it fetches exactly the rows and columns you asked for — nothing more.

KeywordJob
SELECTChoose which fields (columns) to show
FROMName the table to look in
WHEREFilter to rows meeting a condition
INSERT INTOAdd a new record

An analogy: a filing cabinet

The database is the cabinet, each table a drawer, each record a folder, each field a labelled slot inside the folder. SELECT is asking a clerk to pull every folder where the “Mark” slot is over 70. INSERT is filing a brand-new folder.

Worked example — querying and adding. To list the names of pupils who scored more than 70:
IDNameMark1Aisha722Omar644Zara91INSERT adds a new row
INSERT files a brand-new record as an extra row.
SELECT Name
FROM Pupils
WHERE Mark > 70;
This returns Aisha and Leah. To add a new pupil:
INSERT INTO Pupils (ID, Name, Mark)
VALUES (4, 'Zara', 91);
Common mistake: writing the query in the wrong order or dropping the FROM. SQL always goes SELECT … FROM … WHERE. Also remember: SELECT * means “all fields”, so use it only when you really want every column.

Tip: put text values in single quotes ('Zara') but leave numbers unquoted (91). Getting quoting right is half of writing correct SQL.

Get the printable worksheet →
← Files & Data → Binary Numbers
← Sasta Basta home All subjects