Databases and SQL: Computer Science 0478 (Cambridge O Level / IGCSE)
Syllabus 9.1, 9.2, 9.3, 9.4 · Strand 9 Databases
- Questions
- 10
- Total marks
- 48
- Tier mix
- 10 Core
0 of 10 questions completed
Syllabus coverage
- 9.1 3 questions completed
- 9.2 4 questions completed
- 9.3 2 questions completed
- 9.4 6 questions completed
A database organises related data so it can be stored, searched and updated reliably, and syllabus topic 9 focuses on the simplest form: a single table. Designing one starts by turning a real storage requirement into fields (the columns, each with a suitable basic data type such as text, character, Boolean, integer, real or date/time) and records (the rows), then choosing which field, or combination of fields, can serve as a primary key that uniquely identifies every record and applying validation to keep entries sensible (9.1–9.3).
Once a table exists, structured query language lets you ask it questions without writing a full program. The syllabus limits this to a manageable set of keywords: SELECT and FROM choose which fields and table to read, WHERE filters rows against a condition, AND and OR combine multiple conditions, ORDER BY ASCENDING or ORDER BY DESCENDING sorts the result, and SUM and COUNT summarise numeric or matching data (9.4). Exam questions typically give you a table’s contents and an SQL script, or a table and a requirement, and ask you to work out or write the missing piece, so being able to read a query as a sentence, “select these fields, from this table, where this is true”, pays off quickly.
The exam-style questions below are original, written to match this syllabus objective, and each is followed by a full worked solution so you can check your method step by step.
Question 1
"Locked Room Adventures" runs several escape rooms and stores every booking made for them in a single database table called ROOM_BOOKING, shown below.
| BookingID | TeamName | RoomName | GroupSize | BookingDate |
|---|---|---|---|---|
| BK1001 | The Falcons | Pharaoh's Curse | 4 | 2 March 2026 |
| BK1002 | Night Owls | Pharaoh's Curse | 6 | 2 March 2026 |
| BK1003 | The Falcons | Vault 13 | 4 | 5 March 2026 |
| BK1004 | Quiz Wizards | Vault 13 | 5 | 5 March 2026 |
Which field should be chosen as the primary key for the ROOM_BOOKING table?
Question 2
Bramblewood Beekeeping Collective manages hives across two orchards. It plans to store details of each hive in a single database table called HIVE. A sample of the records it plans to store is shown below.
| HiveID | Location | DateInstalled | QueenPresent | NumberOfFrames | EstimatedHoneyKg |
|---|---|---|---|---|---|
| H01 | Meadow Orchard | 12 April 2024 | Yes | 10 | 18.5 |
| H02 | Meadow Orchard | 12 April 2024 | Yes | 8 | 12.0 |
| H03 | Willow Field | 1 May 2025 | No | 6 | 0.0 |
| H04 | Willow Field | 15 June 2025 | Yes | 12 | 22.75 |
(a) Using the data shown, identify the most suitable field to use as the primary key for the HIVE table. Justify your choice by referring to the table. [2]
(b) State the most suitable basic data type for each of these fields: (i) QueenPresent (ii) EstimatedHoneyKg [2]
(c) The collective wants any new hive record to be rejected unless the value entered for NumberOfFrames is between 1 and 12 inclusive. Identify a suitable validation check for this rule, and describe how it would be applied to a value entered for NumberOfFrames. [3]
Question 3
Echo Peak Studios records every recording session it hosts in a single database table called SESSION, shown below.
| SessionID | ArtistName | Genre | DurationMins | Mastered |
|---|---|---|---|---|
| S01 | Nova Ray | Pop | 90 | True |
| S02 | Echo Drift | Rock | 120 | False |
| S03 | Nova Ray | Jazz | 60 | True |
| S04 | Static Bloom | Rock | 75 | True |
| S05 | Kite String | Pop | 105 | False |
| S06 | Echo Drift | Jazz | 45 | False |
(a) A studio assistant runs this SQL statement:
SELECT ArtistName, Genre, DurationMins
FROM SESSION
WHERE Genre = "Rock" OR Genre = "Jazz"
ORDER BY DurationMins DESCENDING;
Using the table, write out the output produced by this statement. [4]
(b) Write an SQL statement that will output the SessionID and ArtistName of every session where the Genre is "Pop" and the session has already been mastered. [3]
Question 4
A school makerspace tracks every 3D-printing job in a single database table called PRINTJOB, shown below. The Priority field always stores a single letter: H (high), M (medium) or L (low).
| JobID | StudentName | Priority | FilamentGrams | Completed |
|---|---|---|---|---|
| PJ01 | Amara Chen | H | 45 | True |
| PJ02 | Femi Osei | M | 120 | False |
| PJ03 | Amara Chen | L | 30 | True |
| PJ04 | Ravi Patel | H | 60 | False |
| PJ05 | Femi Osei | M | 90 | True |
| PJ06 | Tomasz Nowak | L | 15 | False |
(a) State the most suitable basic data type for the Priority field. [1]
(b) Write an SQL statement to output the JobID and FilamentGrams of every job with Priority "H" or Priority "M", with the job using the largest amount of filament listed first. [4]
(c) Write an SQL statement to calculate the total number of grams of filament used by jobs that have already been completed. [3]
Question 5
A small aquarium keeps details of every fish tank it maintains in a single database table called TANK, shown below.
| TankID | Species | WaterTempC | FishCount | Overcrowded |
|---|---|---|---|---|
| T01 | Clownfish | 25.5 | 18 | False |
| T02 | Neon Tetra | 24.0 | 32 | True |
| T03 | Guppy | 23.5 | 22 | True |
| T04 | Angelfish | 26.0 | 15 | False |
| T05 | Neon Tetra | 24.5 | 28 | True |
| T06 | Clownfish | 25.0 | 20 | False |
An aquarium assistant runs this SQL statement:
SELECT COUNT(TankID)
FROM TANK
WHERE FishCount > 20;
What value does this statement return?
Question 6
Trailhead Bike Rentals stores every bike hire it makes in a single database table called BIKE_RENTAL, shown below.
| RentalID | CustomerName | BikeType | DurationHours | HelmetRequested |
|---|---|---|---|---|
| R201 | Priya Nair | Mountain | 2 | True |
| R202 | Owen Clarke | Road | 3 | False |
| R203 | Priya Nair | Hybrid | 1 | True |
| R204 | Maya Lindqvist | Mountain | 2 | False |
Which field should be chosen as the primary key for the BIKE_RENTAL table?
Question 7
Sunnyvale Tutoring Centre books private lessons and stores details of each one in a single database table called LESSON. A sample of the records it plans to store is shown below. SubjectCode always stores a two-letter code, such as MA for Mathematics or EN for English.
| LessonID | StudentName | SubjectCode | DurationMins | Attended |
|---|---|---|---|---|
| L01 | Kofi Mensah | MA | 45 | True |
| L02 | Ines Duarte | EN | 60 | True |
| L03 | Kofi Mensah | SC | 30 | False |
| L04 | Ravi Desai | MA | 45 | True |
(a) Using the data shown, identify the most suitable field to use as the primary key for the LESSON table. Justify your choice by referring to the table. [2]
(b) State the most suitable basic data type for each of these fields: (i) SubjectCode (ii) Attended [2]
(c) The centre wants any new lesson record to be rejected unless the value entered for SubjectCode is exactly two characters long. Identify a suitable validation check for this rule, and describe how it would be applied to a value entered for SubjectCode. [3]
Question 8
Greenfield Weather Station records readings taken at two sites in a single database table called READING, shown below.
| ReadingID | StationName | TemperatureC | RainfallMm | Sunny |
|---|---|---|---|---|
| RD01 | North Ridge | 18.0 | 2.0 | True |
| RD02 | North Ridge | 21.0 | 0.0 | True |
| RD03 | South Bay | 25.0 | 5.5 | False |
| RD04 | South Bay | 20.0 | 12.0 | False |
| RD05 | North Ridge | 15.0 | 8.0 | False |
(a) A student runs this SQL statement:
SELECT AVG(TemperatureC)
FROM READING
WHERE StationName = "North Ridge";
Using the table, work out the value produced by this statement, showing your working. [3]
(b) Write an SQL statement that will output the average TemperatureC of every reading where RainfallMm is greater than 5. [3]
Question 9
Peak Trail Running Club records the results of every timed run in a single database table called RACE_TIME, shown below.
| RunnerID | RunnerName | TrailName | TimeMinutes | Finished |
|---|---|---|---|---|
| RT01 | Jonas Berg | Ridge Loop | 42 | True |
| RT02 | Aisha Rahman | Ridge Loop | 38 | True |
| RT03 | Jonas Berg | Forest Trail | 55 | True |
| RT04 | Priya Shah | Forest Trail | 47 | False |
| RT05 | Aisha Rahman | Forest Trail | 50 | True |
A club member runs this SQL statement:
SELECT MIN(TimeMinutes)
FROM RACE_TIME;
What value does this statement return?
Question 10
Neon Arcade tracks every game played in a single database table called GAME_SCORE, shown below. PrizeClaimed records whether a prize has already been given for that score.
| ScoreID | PlayerName | GameName | Points | PrizeClaimed |
|---|---|---|---|---|
| SC01 | Leah Fischer | Pixel Racer | 3800 | True |
| SC02 | Marco Silva | Star Blaster | 3100 | False |
| SC03 | Leah Fischer | Star Blaster | 5600 | True |
| SC04 | Devon Clarke | Pixel Racer | 2800 | False |
| SC05 | Marco Silva | Pixel Racer | 6200 | True |
| SC06 | Devon Clarke | Star Blaster | 3900 | False |
(a) Write an SQL statement to output the PlayerName and Points of every score for "Pixel Racer" where the Points are greater than 3000, with the highest Points listed first. [4]
(b) Write an SQL statement to find the highest Points value recorded for "Star Blaster". [2]
(c) Write an SQL statement to output the PlayerName and GameName of every score where a prize has already been claimed and the Points exceed 4000. [3]