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.
Tables, records and fields
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
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.
| Keyword | Job |
|---|---|
| SELECT | Choose which fields (columns) to show |
| FROM | Name the table to look in |
| WHERE | Filter to rows meeting a condition |
| INSERT INTO | Add 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.
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);
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.