EEasy IGCSELabTracker

On a phone the notes, quizzes and tracker work fine. The 3D models and the practice lab are made for a laptop.

Specification points 9.1–9.4 ·

single-table databases (fields, records, validation), data types, primary keys and SQL queries on one table.

1Single-table databases

Definition

Database — a structured collection of data, stored so that it can be searched and queried. A single-table database stores all its data in one table.

Record — one row of the table: all the data about one item, person or event.

Field — one column of the table: one item of data stored for every record. Every record has the same fields.

Table: BIKE BikeID Model Type Gears DailyRate Available LastService B001 Trailblazer M 21 12.50 TRUE 14/03/2026 B002 Sprint 5 R 18 15.00 FALSE 02/05/2026 B003 CityGo H 7 9.00 TRUE 20/01/2026 B004 Ridgeback M 24 14.00 TRUE 11/04/2026 B005 Aero 2 R 22 18.50 TRUE 28/02/2026 B006 Commuter H 3 8.00 FALSE 09/05/2026 field (column) one item of data for every record field names record (row) all the data about one bike primary key — a different value in every record 7 fields · 6 records
Figure 1. The BIKE table of a bike-hire shop, used in every example in this topic.

Field, record or primary key?

Loading the interactive…

  • The table and each field get a meaningful name. Field names are one word with no spaces (DailyRate, not Daily rate).
  • The row of field names is not a record: BIKE has 7 fields and 6 records.

2Data types

Each field is given the data type that suits the data it will hold.

Data type Holds Field in BIKE
Text / alphanumeric any mix of letters, digits and symbols Model, BikeID (e.g. B004)
Character exactly one character Type (M, R or H)
Boolean one of two values: TRUE / FALSE Available
Integer a whole number Gears
Real a number with a decimal part DailyRate
Date/time a date and/or a time LastService

Choose by what the data is, not by how it looks: a value made of digits that is never used in a calculation — phone number, ID code, postcode — is text (it may start with 0 or contain +, spaces or letters). Money is real.

3Primary key

Definition

Primary key — a field that uniquely identifies each record in a table: no two records can ever have the same value in it.

Purpose: every record can be found and referred to without confusion; a duplicate record cannot be stored, because the database rejects a repeated primary-key value.

Choosing one: pick the field whose values are guaranteed to be different for every record, including records added later — usually an ID or code field. In BIKE that is BikeID. Model is unique in these six records, but a second bike of the same model could be bought. Names, dates, prices and counts can all repeat. If no field is guaranteed unique, add an ID field (e.g. MemberID) and make it the primary key.

4Defining a table from data storage requirements

A 9.1 question describes what must be stored; you answer with the table name, a field for each item of data, a data type for each field, the primary key and suitable validation.

Validation is an automatic check that data entered into a field is reasonable and follows set rules; data that fails is rejected. It cannot tell whether data is correct. The checks are the ones from 7.5: range, length, type, presence, format, check digit.

Requirement: A bike-hire shop needs to store, for each bike: a code of B followed by three digits, the model name, the type (M = mountain, R = road, H = hybrid), the number of gears (1–30), the price per day, whether it is available and the date of its last service.

Field Data type Validation
BikeID (primary key) text presence check; format check: B then 3 digits
Model text presence check; length check: at most 20 characters
Type character length check: exactly 1 character
Gears integer range check: 1 to 30
DailyRate real range check: greater than 0
Available Boolean none needed — only TRUE or FALSE can be stored
LastService date/time type check: a valid date; range check: not in the future

Table name: BIKE.

5SQL queries

SQL (structured query language) is used to write scripts that query a database: they fetch only the data asked for. An SQL script is one or more SQL statements; each query statement ends with ;.

SELECT <field>, <field>     -- or SELECT * for every field
FROM <table>
WHERE <condition>           -- optional
ORDER BY <field> ASC;       -- optional; DESC for descending
Keyword What it does Question wording that signals it
SELECT chooses the fields to show, in that order; * = all fields "show / display / list the …"
FROM names the table —
WHERE keeps only the records that meet the condition "only those …", "every bike that …"
AND both conditions must be true "… and …"
OR at least one condition must be true "either … or …"
ORDER BY … ASC sorts ascending: A → Z, smallest first "in alphabetical order", "lowest first"
ORDER BY … DESC sorts descending: Z → A, largest first "reverse order", "highest first"
SUM(field) adds up a numeric field over the selected records "total …"
COUNT(*) counts the selected records (COUNT(field) is also used) "how many …"

Conditions compare a field with a value using = <> < > <= >=. Write the value to match the field's data type: text, character and dates in quotes ('M', 'Sprint 5'); integers and reals as plain numbers (24, 13.00); Boolean as TRUE or FALSE.

Working out the output of a query

SELECT Model, DailyRate FROM BIKE WHERE Available = TRUE AND DailyRate < 13.00 ORDER BY DailyRate ASC; 1 WHERE — test every record BikeID Available = TRUE DailyRate < 13.00 keep? B001 TRUE ✓ 12.50 ✓ yes B002 FALSE ✗ 15.00 ✗ no B003 TRUE ✓ 9.00 ✓ yes B004 TRUE ✓ 14.00 ✗ no B005 TRUE ✓ 18.50 ✗ no B006 FALSE ✗ 8.00 ✓ no AND: both conditions must be true to keep a record. 2 SELECT — named fields Model DailyRate Trailblazer12.50 CityGo9.00 still in table order 3 ORDER BY … ASC Model DailyRate CityGo9.00 Trailblazer12.50 smallest DailyRate first = the output
Figure 2. Apply WHERE to every record, then keep the SELECT fields, then sort.

Build an SQL query on BIKE

Loading the interactive…

More examples on BIKE

OR and descending order:

SELECT BikeID, Model, Gears
FROM BIKE
WHERE Type = 'R' OR Gears > 22
ORDER BY Model DESC;
BikeID Model Gears
B002 Sprint 5 18
B004 Ridgeback 24
B005 Aero 2 22

B002 and B005 are road bikes; B004 has more than 22 gears. Sorted Z → A by Model.

SUM and COUNT return one value, not a list of records:

Total daily rate of mountain bikes
SELECT SUM(DailyRate)
FROM BIKE
WHERE Type = 'M';

Output: 26.50 (12.50 + 14.00)

Number of available bikes
SELECT COUNT(*)
FROM BIKE
WHERE Available = TRUE;

Output: 4 (B001, B003, B004, B005)

Traps
  • Repeat the field in OR/AND: WHERE Type = 'R' OR Type = 'H', never WHERE Type = 'R' OR 'H'.
  • Output fields: only the SELECT fields appear, in the SELECT order — even if WHERE or ORDER BY uses another field.
  • Quotes go round text, character and date values only — never round numbers or TRUE/FALSE.

Quick check

13 multiple-choice questions. Pick an answer to see whether it is right and why.

  1. A table PET stores the name, species and age of 8 pets, under a row of field names. How many fields and records does it have?

  2. Which is a suitable field name for a member's date of birth?

  3. Which data type should a field holding a mobile phone number have?

  4. The field Size always holds exactly one of the letters S, M or L. Which data type suits it best?

  5. A table STUDENT has the fields StudentID, Surname, DateOfBirth and FormGroup. Which field should be the primary key?

  6. What happens when a new record is entered with a primary-key value that is already in the table?

  7. The field Rating must hold a whole number from 1 to 5. Which validation suits it?

  8. PET has three records with (Name, Age) of ('Rex', 4), ('Milo', 9) and ('Zed', 6). What is the output of SELECT Name FROM PET WHERE Age > 5 ORDER BY Name ASC;?

  9. ITEM has four records with (Code, Colour, Stock) of ('A1', 'Red', 0), ('A2', 'Blue', 7), ('A3', 'Red', 5) and ('A4', 'Green', 0). How many records does SELECT * FROM ITEM WHERE Colour = 'Red' OR Stock = 0; show?

  10. ITEM has four records with (Code, Colour, Stock) of ('A1', 'Red', 0), ('A2', 'Blue', 7), ('A3', 'Red', 5) and ('A4', 'Green', 0). What is the output of SELECT SUM(Stock) FROM ITEM WHERE Colour = 'Red';?

  11. TRIP has four records with (Town, Miles) of ('York', 40), ('Bath', 25), ('Hull', 40) and ('Ely', 60). What is the output of SELECT COUNT(*) FROM TRIP WHERE Miles >= 40;?

  12. TRIP has four records with (Town, Miles) of ('York', 40), ('Bath', 25), ('Hull', 40) and ('Ely', 60). What is the output of SELECT Town FROM TRIP WHERE Miles < 50 ORDER BY Town DESC;?

  13. Which WHERE line keeps the records whose Town is York or Bath?

Exam-style questions

Write your answer, then show the answer and compare. Nothing here is marked for you: you decide how close you were. What you write is saved in this browser.

Questions

1

State the number of fields and the number of records in CLUB.

2 marks
2

Suggest the most suitable data type for Gender, Age, Fee and Junior.

4 marks
3

Identify the primary key of CLUB and explain why Surname would not be a suitable primary key.

2 marks
4

The club adds a field PhoneNumber. State its data type and give a reason.

2 marks
5

Suggest a suitable validation check for Age, for MemberID and for Surname. Describe each check.

3 marks
6

Give the output of:

SELECT Surname, Age
FROM CLUB
WHERE Junior = TRUE AND Fee = 30.00
ORDER BY Age DESC;
3 marks
7

Give the output of:

SELECT MemberID
FROM CLUB
WHERE Gender = 'M' OR Age < 14;
2 marks
8

Give the output of SELECT COUNT(*) FROM CLUB WHERE Fee > 28.00; and of SELECT SUM(Fee) FROM CLUB WHERE Junior = FALSE;

2 marks
9

Complete the script to show the surname and join date of every female member, in alphabetical order of surname.

SELECT Surname, ..........
FROM ..........
WHERE ..........
ORDER BY ..........;
4 marks
10

Write an SQL query to show the MemberID and Age of every member aged 16 or over who pays less than 50.00.

4 marks
11

This query should show the surname and age of every member older than 15 or younger than 13. Identify and correct three errors.

SELECT Surname Age
FROM CLUB
WHERE Age > 15 OR < 13
3 marks
12

A library needs to store, for each book: its ISBN (13 digits, unique to each book), the title, the number of pages, the price, whether it is on loan and the date it was added. Define a single-table database for this: give the table name, a field name and data type for each item, the primary key and one validation check.

6 marks

How well do you know this?

Rate each specification point. It is saved to your tracker as a new revision round.

All points:
  • 9.1Define a single-table database from given data storage requirements
  • 9.2Suggest suitable basic data types
  • 9.3Understand the purpose of a primary key and identify a suitable primary key for a given database table
  • 9.4Read, understand and complete structured query language (SQL) scripts to query data stored in a single database table

Settings

Your subjects

Untick the subjects you don't take. They leave the menu, the home page and the tracker. Your ratings are kept, so you can bring a subject back at any time.

Page style

Colours