DB

9.Databases

Single-table databases, data types, keys, validation, verification and SQL

Learning Objectives

By the end of this lesson, you will be able to:

  • Explain what a database is and describe why databases are useful for storing, retrieving, sorting and searching data.
  • Identify fields and records and distinguish a field (column) from a record (row).
  • Describe a flat-file/single-table database and recognise how it differs from a relational database.
  • Suggest suitable basic data types for database fields, including text/alphanumeric, character, Boolean, integer, real, date/time and currency.
  • Identify a suitable primary key and explain how a foreign key can link tables.
  • Explain and apply validation and verification checks, including length, format, range, type, presence, check digit, visual and double-entry checks.
  • Read, understand and complete SQL statements using SELECT, FROM, WHERE, AND, OR, LIKE, ORDER BY, SUM and COUNT.
  • Work through database questions, predict SQL output and choose appropriate fields, data types and keys.

Key Terms

  • Database- an organised, structured collection of data that can be stored and managed efficiently.
  • Table- a collection of records with a similar structure.
  • Field- one piece of information about a person, item or object; shown as a column.
  • Record- a collection of related fields about one person, item or object; shown as a row.
  • Flat-file / single-table database- a database where data is stored in a table or separate tables, with each table made from records and fields; the IGCSE notes focus on single-table databases.
  • Relational database- a database made from multiple related tables; the notes include it for awareness beyond the basic IGCSE single-table focus.
  • Data type- the kind of data that a field can hold.
  • Primary key- a unique field used to identify each record in a table.
  • Foreign key- a field that refers to the primary key in another table so tables can be linked.
  • Validation- a set of rules controlling what data can be entered into a field.
  • Verification- a check that confirms entered data is correct and matches the intended information.
  • SQL- Structured Query Language, used to interact with a DBMS and query/manipulate database data.
  • DBMS- a database management system used to work with databases.
  • Wildcards- special matching symbols; the notes show * for all columns and % with LIKE for pattern matching.
  • Aggregation- using functions such as SUM and COUNT to calculate totals or counts.
  • Secondary storage- storage on which database and text-file information can be stored so it remains available when an application is closed.

9.1 Define a single-table database from given data storage requirements

A database is an organised collection of data. The notes describe databases as structured, persistent collections that allow data to be arranged and stored in tables for querying and manipulation.

Database overview video from the notes:Watch the Database overview video

  • Databases are useful when working with large amounts of data.
  • Database information is stored on secondary storage.
  • A database may be stored on a remote server so multiple users can access it at the same time, which is useful for online systems.
  • Data can be sorted and searched efficiently using database structures.
  • The notes state that databases are more secure than text files.

Familiar example: school records

A school database can store student names, class IDs, marks and other information. A teacher can search for a student, retrieve a record, or sort records without keeping the information in a long plain-text document.

Types of databases shown in the notes

  • Flat-file database — the type covered in the IGCSE notes.
  • Relational database — multiple related tables; shown for awareness as a topic beyond the basic single-table focus.

Visualise the difference

Flat-file / single table
IDCustomerCountryCityDate
1Dongford InternationalUSANew York13.09
2Stateford Co.FranceParis14.11
Relational idea
Students
Courses
linked data (for example, lecturer/course information)

Fields, records and text files

  • A field is one piece of information relating to one person, item or object and is represented by a column.
  • A record is a collection of fields relating to one person, item or object and is represented by a row.
  • A text file is useful when working with small amounts of data. Text files are stored on secondary storage and read into a program when needed.
  • Text files keep information when the application is closed.
  • Each entry can be stored on a new line or separated by a special identifier such as a comma.
  • It can be difficult in a text file to know exactly where a record begins and ends.

Exam visual cue: remember column vs row

Field = column.Record = row.The annotated database diagram in the notes uses a field/column and a record/row to make this distinction visible.

Single-table databases

  • A single-table database is a simple form of database where all the data is stored in a single table.
  • A flat-file database consists of one or more tables.
  • Each table has a number of records (rows).
  • Each record has a number of separate fields (columns).
  • Records in the same table have the same structure.
  • Each field has a defined data type.
  • Each table should have a primary key so each record can be uniquely identified.
  • Database table fields can have validation rules such as length, format, range, presence and custom rules.

Example database table from the notes

The employee example shows a table holding employee data. The notes also show a multi-table database diagram withPublishers,Books,AuthorsandInventorylinked together.

Data types used in database fields

  • Text/alphanumeric — text data.
  • Character — one character.
  • Boolean — true/false values (or Yes/No in the database software example).
  • Integer — a whole number.
  • Real — a decimal number.
  • Date/time — a date or time value.
  • The notes also show Currency as a type in database software.

Data-type examples from the notes

FieldSuitable typeWhy
EmployeeIDIntegerA whole-number identifier
SalaryRealMay contain decimal values
GenderCharacter / BooleanThe notes show Character for M/F and Boolean for True/False where appropriate
BirthDateDate/timeStores a date value

Primary keys

  • A primary key is a unique field that identifies a record in a table.
  • Each record must be uniquely identifiable, so no two records should have the same primary-key value.
  • A primary key supports data integrity and efficient data retrieval.
  • A primary key can also be used to establish relationships between tables.
  • Sometimes one field in the existing data can be used; in other situations an additional field must be created.

Choosing a key

Examples in the notes includeStudent_IDin a school database,Car_Registrationin a car database andProduct_IDin a shop database. In the dance-club worked example,MemberIDis the most suitable primary key because it identifies each member uniquely.

Validation

  • A validation rule controls what data can be entered into a field.
  • Validation helps maintain data integrity and prevents invalid input from causing incorrect results or system problems.
  • The notes list length, format, range, presence and custom rules such as Apprentice, Expert or Master.
  • Validation can be assigned to any field of a table.
CheckPurpose and example
Length checkChecks the number of characters. Example: a phone number may have to be eleven characters; a password example in the notes is 8–20 characters.
Format checkChecks an exact pattern. Example: a product code may be two letters followed by five numbers; an email address should follow its required pattern.
Range checkChecks that a number is within an acceptable range. Examples include age 18–65, dog age 0–40, or marks 0–100.
Presence checkMakes sure a required field is not blank.
Type checkEnsures the entered value is of the expected type, such as an integer where an integer is required.
Check digitUses an extra digit calculated from the other digits to verify numeric data such as a credit-card number. The same algorithm is applied again; a different result indicates an incorrect code.

Employee-field validation examples from the notes

  • FirstName and LastName: presence/length rules so names are not empty and do not exceed a limit.
  • Gender: Character value restricted to M or F.
  • IsManager: Boolean value must be True or False.
  • EmployeeID: positive integer.
  • Salary: positive real number.
  • BirthDate and JoinDate: valid date format.

Verification

  • Verification checks whether entered data is correct, valid and consistent with the intended information.
  • Visual check — a person manually reviews the entered data. The notes give a bank-teller checking a customer signature as an example.
  • Double-entry check — the same data is entered twice independently and the entries are compared. The notes give entering an email address twice when creating an account as an example.

Worked validation example

For the student-grades table in the notes, two suitable validation checks are:

  • StudentID: a length check to ensure seven characters are entered.
  • FirstName and LastName: a presence check so a record cannot be entered without the student name.

The notes also show a type check on MarkSubmitted so only Y or N are entered, and a range check on Mark so only numbers from 0 to 100 are accepted.

Interactive: validation checker

Choose a check and a sample value. The messages use only the validation rules shown in the notes.

Enter a value and press Check.

Activity 1: Fields, records and data types

Difficulty: Easy • Estimated time: 8 minutes

For a school table with StudentID, StudentName, Mark, DateOfBirth and Passed, identify which are fields and state a suitable data type for each.

  • Every heading is a field (column): StudentID, StudentName, Mark, DateOfBirth and Passed.
  • StudentID and Mark are suitable as integer values.
  • StudentName is suitable as text/alphanumeric.
  • DateOfBirth is suitable as date/time.
  • Passed is suitable as Boolean (True/False or Yes/No).

Activity 2: Validation and keys

Difficulty: Medium • Estimated time: 10 minutes

A school table contains StudentID, Name, Mark and Email. Suggest a primary key and two suitable validation checks, then explain one verification method.

  • StudentID is a suitable primary key when its values uniquely identify each student.
  • A range check can ensure Mark is between 0 and 100.
  • A presence check can ensure Name is not blank.
  • A format check can ensure Email follows the required pattern.
  • A visual check can be used to inspect entered data for reasonable accuracy, or a double-entry check can compare the same value entered twice.

Check Your Understanding: Single-table databases, validation and verification

  • A field is one piece of information about a person, item or object.
  • A field is represented by a column in a database table.
  • A record is a collection of related fields.
  • A record is represented by a row in a database table.
  • It uniquely identifies each record.
  • It prevents two records from using the same key value.
  • It helps maintain data integrity.
  • It supports efficient retrieval and can help establish relationships between tables.
  • A database is organised into tables containing fields and records, while text files store entries as lines or separated values.
  • Databases are designed for efficient searching and sorting of data.
  • A text file is especially useful for smaller amounts of data.
  • The notes state that databases are more secure than text files.
  • It checks whether an entered value lies within an acceptable range.
  • Values outside that range are rejected.
  • For example, a mark can be restricted to 0–100.
  • Another example in the notes is an age restricted to a defined range such as 18–65.
  • Validation controls what data is allowed to be entered.
  • Verification checks that the entered data is correct and matches the intended information.
  • A range or presence check is a validation example.
  • A visual check or double-entry check is a verification example.

9.2 Suggest suitable basic data types

When setting up a database, each field must be given an appropriate data type. The notes show groups such as Alphanumeric (Text, Memo), Numeric (Number, Currency, etc.), Date/Time and Boolean (Yes/No).

The source image uses Microsoft Access as an example of database software where each field is assigned a data type.

Data typeSimple meaning from the notes
Text / AlphanumericStores text data, such as names and codes.
CharacterStores a single character.
IntegerStores a whole number.
RealStores a decimal number.
CurrencyStores a monetary value.
Date/TimeStores a date or time value.
Boolean (Yes/No)Stores one of two logical values, such as True/False or Yes/No.

Cars database example from the notes

The notes givecar_id: integer,make: text/alphanumeric,model: text/alphanumeric,colour: text/alphanumericandprice: real.

car_idmakemodelcolourprice
1Peugeot2008Red24950
2MazdaMX5Blue17995
3CitroenDS4Black21450
4FordPumaWhite19500

Familiar example: mobile shopping app

A product name needs text, a quantity needs a whole number, a price can be a real/currency value, and “in stock” can be Boolean. The important exam skill is matching the type to the data that the field must hold.

Quick data-type decision tool

Text / Alphanumeric is a suitable choice.

Activity 1: Choose the data type

Difficulty: Easy • Estimated time: 7 minutes

Choose a suitable data type for: Student Name, Age, Average Mark, Gender, Date Joined and IsPresent.

  • Student Name — Text/alphanumeric.
  • Age — Integer.
  • Average Mark — Real.
  • Gender — Character or another suitable type when only a single character is required.
  • Date Joined — Date/Time.
  • IsPresent — Boolean.

Activity 2: Explain your choice

Difficulty: Medium • Estimated time: 8 minutes

A shop database contains ProductCode, ProductName, Quantity, Price and InStock. Give a suitable type for every field and explain one possible validation rule for Price.

  • ProductCode — Text/alphanumeric, because a code can contain letters and digits.
  • ProductName — Text/alphanumeric, because it stores words.
  • Quantity — Integer, because it is a whole number.
  • Price — Real or Currency, because it stores a monetary/decimal amount.
  • InStock — Boolean, because it has two states.
  • A range check can restrict Price to an acceptable minimum/maximum; the notes also show Currency as a database type.

Check Your Understanding: Basic data types

  • A data type describes the kind of data a field can hold.
  • The type is chosen when the table is designed.
  • The type should match the information stored in the field.
  • Examples from the notes include integer, real, text, character, Boolean and date/time.
  • ProductName stores text rather than a whole-number quantity.
  • An integer data type is designed for whole numbers.
  • Text/alphanumeric is suitable for names and words.
  • Choosing the correct type helps the database store and validate the data appropriately.
  • A number type is appropriate because a mark is numeric.
  • An integer is suitable when marks are stored as whole numbers.
  • A real is suitable when decimal marks are permitted.
  • The choice should match the exact data requirements of the field.
  • Boolean is suitable when the field represents two logical states.
  • The notes use Boolean as True/False or Yes/No.
  • A validation rule can further restrict the entered values to the required two choices.
  • A Character type could represent a single character such as Y or N where the database design specifically uses characters.
  • Currency is designed to store monetary values.
  • The database software example in the notes includes Currency as a data type.
  • Text would treat the price as characters rather than a monetary value.
  • Choosing the suitable numeric/money type supports appropriate storage and checking of the value.

9.3 Understand the purpose of a primary key and identify a suitable primary key for a given database table

The primary key in a relational database uniquely identifies each record (row) in a table. The notes emphasise that no two records should have the same key value.

  • A primary key is a unique identifier for each record.
  • It helps maintain data integrity.
  • It supports efficient retrieval of records.
  • It can provide a way to establish relationships between tables.
  • A suitable key can be generated manually or an additional field can be created when no existing field is unique.

Dance club worked example

The Members table containsMemberID, FirstName, LastNameandDateJoined. The most suitable primary key isMemberIDbecause it is intended to uniquely identify members.

MemberIDFirstNameLastNameDateJoined
1ZarmeenHussain2024-01-19
2FynBall2024-02-01
3GeorgeJohnson2024-02-25
4EllaFranks2024-03-04

Foreign keys

  • A foreign key is a column or group of columns in a relational database that provides a link between data in two tables.
  • It refers to the primary key of another table.
  • It acts as a cross-reference so related records can be connected.
  • The notes illustrate an ArtistID primary key in an Artists table and an ArtistID foreign key in an Albums table, and also a DirectorID relationship between Directors and Movies.

Visualise a table relationship

Artists

ArtistID← primary key

Albums

ArtistID← foreign key

Interactive: find the most suitable key

Click a field. The checker uses the idea from the notes: a good primary key should uniquely identify each record.

Select a field.

Activity 1: Choose a primary key

Difficulty: Easy • Estimated time: 7 minutes

A customer table has CustomerID, FirstName, LastName, DOB and PhoneNumber. Select the most suitable primary key and explain your reason.

  • CustomerID is the strongest choice because it is intended as a unique identifier.
  • The primary-key value should not repeat for different records.
  • FirstName and LastName may repeat.
  • DOB may repeat.
  • A unique customer ID supports reliable record identification.

Activity 2: Explain a foreign key

Difficulty: Medium • Estimated time: 8 minutes

A school has Students and Classes tables. Explain how a foreign key could connect a student record to a class record.

  • The Classes table can have a primary key such as ClassID.
  • The Students table can contain ClassID as a foreign key.
  • The foreign key refers to the ClassID primary key in Classes.
  • The two tables can therefore be related through the shared identifier.
  • This allows data in the two tables to be connected without repeating all class information.

Check Your Understanding: Primary and foreign keys

  • It uniquely identifies each record.
  • Its value should not be duplicated for different records.
  • It should provide a reliable way to distinguish records.
  • It helps maintain data integrity.
  • Different people can have the same name.
  • A repeated name would fail the uniqueness requirement.
  • A key must uniquely identify each record.
  • An assigned ID such as StudentID is more suitable when it is unique.
  • A foreign key is a field that refers to a primary key in another table.
  • It is used to create a link between tables.
  • It acts as a cross-reference to related data.
  • The notes illustrate fields such as ArtistID or DirectorID being used for these relationships.
  • Do not choose a field just because it is a field in the table.
  • Recognise that repeated values mean the field cannot uniquely identify every record.
  • Add a new field designed to be unique, such as a performance number.
  • Use that new unique field as the primary key.
  • It gives each record a unique identifier.
  • It makes it easier to locate a particular record.
  • It helps prevent ambiguity between similar records.
  • It supports data integrity and can help establish relationships between tables.

9.4 Read, understand and complete structured query language (SQL) scripts to query data stored in a single database table

SQL (Structured Query Language)is a programming language used to interact with a DBMS. The notes explain that database information is stored in records, each record can contain fields, and SQL is used to manipulate and query that data.

SQL/database overview video from the notes:Watch the SQL/database overview video

  • The notes state that SQL can select data, order data, sum data and count data.
  • SQL statements can be used to create, delete, modify and manipulate records, but for IGCSE the SELECT statement is the key focus in the notes.
  • The notes show a strict pattern for SELECT statements: SELECT, FROM, WHERE and optional ORDER BY.

The SELECT structure

SELECT

fields to return

FROM

table to use

WHERE

search condition

ORDER BY

optional sorting

SELECT <field(s)>
FROM <table>
WHERE <condition>
ORDER BY <field> ASC

SQL commands and operators in the notes

ItemWhat it doesExample from the notes
SELECTRetrieves data from a database table.SELECT * FROM users;
FROMSpecifies the table(s) from which data is retrieved.SELECT name, age FROM users;
WHEREFilters rows using a condition.WHERE age > 30;
ANDRequires multiple conditions to be true.WHERE age > 18 AND city = 'New York';
ORReturns a row when at least one condition is true.WHERE age < 18 OR city = 'New York';
*Selects all columns.SELECT * FROM Customers;
LIKE + %Matches a pattern; % is used as a wildcard in the LIKE operator.WHERE name LIKE 'J%';
ORDER BYSorts the returned data, using ASC or DESC.ORDER BY age DESC;
SUMAdds the values in a field and outputs the total.SELECT SUM(Salary) FROM tbl_people;
COUNTCounts rows matching the criteria.SELECT COUNT(*) FROM tbl_people WHERE Salary > 50000;

Python connection example shown in the notes

One source page shows a Python program connecting to a database and passing an SQL statement. The notes explicitly say that most of this Python code is beyond the IGCSE syllabus and that, at this stage, you do not need to worry about it. The IGCSE focus remains understanding the SQL statements.

SQL walkthrough: world database examples

Example 1 — retrieve one field

The notes show:

SELECT population
FROM world
WHERE name = "Germany"

Example 2 — retrieve Albania population

The query returns the population for Albania; the screenshot shows the output2821977.

SELECT population
FROM world
WHERE name = "Albania"
Output:2821977

Example 3 — select several fields

The notes select name, continent, area, population, gdp and capital for Algeria.

SELECT name, continent, area, population, gdp, capital
FROM world
WHERE name = "Algeria"
The screenshot begins the output with Algeria, Africa, 2381741, 38700000…

Example 4 — LIKE, AND and ORDER BY

The notes use a wildcard pattern, a second condition and ascending sorting.

SELECT name, continent, area, population, gdp, capital
FROM world
WHERE name LIKE "A%" AND population > 10000000
ORDER BY name ASC

Read it as: return the listed fields for names beginning with A, only when population is greater than 10,000,000, and sort the names in ascending order.

Example 5 — COUNT

The notes count the rows where continent is Asia. The screenshot shows an output of3.

SELECT COUNT(*)
FROM world
WHERE continent = "Asia"
Output:3

Example 6 — SUM

The notes add the populations of records where continent is Europe. The screenshot shows114026555.

SELECT SUM(population)
FROM world
WHERE continent = "Europe"
Output:114026555

Worked Example — tbl_animals

Complete the SQL statement

The source notes provide this table:

AnimalBreedingNumber of Young
Red FoxYes4–6
RabbitYes4–12
African ElephantYes1
Blue WhaleNo1
OrangutanYes1
PolarBearYes1–3
DolphinYes1
KangarooYes1
LionYes1–6
PenguinYes1

Task: display all animal breeds that are currently breeding and where there was only one young born this year.

SELECT Animal
FROM tbl_animals
WHERE Breeding = "Yes" AND Number of Young = 1

The source answer awards one mark each for SELECT Animal, FROM tbl_animals and the combined WHERE condition.

SQL examples using a Customers table

Select all fields

The notes show:

SELECT * FROM Customers;

The displayed table includes John Doe (30, New York, USA), Jane Doe (25, London, UK) and Peter Lee (40, Paris, France).

Select specific fields and filter by age

SELECT ID, name, age
FROM Customers
WHERE Age > 25;

The shown output includes John Doe, 30 and Peter Lee, 40.

Use LIKE with a wildcard

SELECT Name, Country
FROM Customers
WHERE Country LIKE 'U%';

The shown output includes John Doe — USA and Jane Doe — UK.

Use OR

SELECT *
FROM Customers
WHERE City = 'London' OR City = 'Paris';

The worked page shows the matching London record in the output table and demonstrates that OR tests alternative conditions.

Use ORDER BY

SELECT *
FROM Customers
ORDER BY age DESC;

The notes show the rows ordered from the highest age to the lowest age.

Creating and inserting tables shown in the notes

Example 1 — CREATE TABLE Students

CREATE TABLE Students (
    StudentID INT AUTO_INCREMENT PRIMARY KEY,
    Name VARCHAR(50),
    Age INT,
    Gender VARCHAR(10),
    Grade INT
);

Example 1 — INSERT Students data

INSERT INTO Students (StudentID, Name, Age, Gender, Grade) VALUES
(1, 'Nuriya', 15, 'Female', 95),
(2, 'Artur', 15, 'Male', 68),
(3, 'Danial', 15, 'Male', 70),
(4, 'Inaaya', 15, 'Female', 95),
(5, 'Harsh', 15, 'Male', 90),
(6, 'Ivan', 15, 'Male', 80),
(7, 'Eker', 15, 'Male', 65),
(8, 'Beiza', 15, 'Female', 81),
(9, 'Nicholas', 15, 'Male', 66),
(10, 'Darius', 15, 'Male', 62),
(11, 'Samina', 15, 'Female', 90),
(12, 'Emir', 15, 'Male', 95);

Example 1 — Students queries

SELECT Name, Age
FROM Students
WHERE Gender = 'Female' AND Grade > 90
ORDER BY Age;

Shown result: Nuriya and Inaaya.

SELECT COUNT(*)
FROM Students
WHERE Gender = 'Male';

Shown result: 8.

SELECT SUM(Grade)
FROM Students;

The screenshot shows a total of 957.

Example 2 — CREATE TABLE Sales

CREATE TABLE Sales (
    ProductID INT PRIMARY KEY,
    ProductName VARCHAR(255),
    Category VARCHAR(50),
    QuantitySold INT,
    UnitPrice DECIMAL(10, 2)
);

Example 2 — INSERT Sales data

INSERT INTO Sales (ProductID, ProductName, Category, QuantitySold, UnitPrice) VALUES
(1, 'Laptop', 'Electronics', 10, 800.00),
(2, 'Smartphone', 'Electronics', 20, 500.00),
(3, 'Desk Chair', 'Furniture', 5, 120.00),
(4, 'LED TV', 'Electronics', 15, 1000.00),
(5, 'Coffee Table', 'Furniture', 8, 150.00);

Example 2 — SUM and COUNT

SELECT SUM(QuantitySold) AS TotalQuantity, COUNT(*) AS QuantitySold
FROM Sales;

Shown output: TotalQuantity = 58 and QuantitySold = 5.

Example 2 — combining WHERE with aggregation

SELECT country, SUM(QuantitySold) AS TotalQuantity
FROM Sales
JOIN Customers ON Sales.ProductID = Customers.customer_id
WHERE country = 'UK'
GROUP BY country;

Shown result: UK, 20. The notes also show the equivalent version using Customers.country and Sales.QuantitySold explicitly.

Interactive SQL visualiser

Use the buttons to see how SELECT, WHERE and ORDER BY change the same small Customers dataset.

Open SQL Compiler
SELECT * FROM Customers;

Activity 1: Complete a SELECT query

Difficulty: Easy • Estimated time: 8 minutes

Using a Customers table, write SQL to return Name and Country for customers whose country begins with U.

SELECT Name, Country
FROM Customers
WHERE Country LIKE 'U%';

Activity 2: Write and explain an SQL query

Difficulty: Medium • Estimated time: 10 minutes

Using the Students table from the notes, write a query to return the names and ages of female students who scored above 90 and order the results by age.

SELECT Name, Age
FROM Students
WHERE Gender = 'Female' AND Grade > 90
ORDER BY Age;

Check Your Understanding: SQL

  • SELECT asks the database to retrieve data.
  • The * wildcard means all columns are selected.
  • The FROM clause then identifies the table being queried.
  • For example, SELECT * FROM Customers; returns all columns from Customers.
  • WHERE filters rows using a specified condition.
  • Only records that satisfy the condition are returned.
  • For example, WHERE age > 30 selects users older than 30.
  • WHERE can be combined with AND or OR for more complex conditions.
  • AND requires all linked conditions to be true.
  • OR returns a row when at least one condition is true.
  • For example, age > 18 AND city = London is more restrictive.
  • For example, city = London OR city = Paris accepts either city.
  • ORDER BY sorts the rows in the returned result.
  • ASC means ascending order.
  • DESC means descending order.
  • For example, ORDER BY age DESC places older ages before younger ages.
  • SUM adds the values in a specified numeric field and returns the total.
  • COUNT counts rows matching the criteria.
  • SUM(Grade) can calculate the total of all grades.
  • COUNT(*) can count the number of matching rows.

Past Paper Questions and Answers from the Notes

The source notes finish with ten database past-paper style question sets and answers. They practise field/record counting, primary keys, data types, SQL queries and predicting outputs.

Exam reminder

The notes repeatedly test the same core skills:record = row,field = column, identify a unique primary key, choose a suitable data type, complete the SQL statement, and give the exact output.

  • Primary key:TVCode, because each TV code is a unique identifier.
  • Data types:TVCode = Text; ScreenSize = Integer; SmartTV = Boolean; Price$ = Real.
  • SQL:
SELECT TVCode, ScreenSize, Price$
FROM TVRange
WHERE SmartTV = YES
  • Primary key: SongNumber, because it is the catalogue number used to identify a song.
  • SongNumber = Text/Alphanumeric.
  • Title = Text/Alphanumeric.
  • Recorded = Date/time.
  • Minutes = Real.
  • SUM(Minutes) FROM Songs WHERE Genre = "rock" finds the total number of minutes of rock music.
  • COUNT(Title) FROM Songs WHERE Genre = "rock" counts the number of rock songs.
SUM (Minutes) FROM Songs WHERE Genre = "rock";
COUNT (Title) FROM Songs WHERE Genre = "rock";
  • Fields = 5; Records = 12.
  • Primary-key purpose: to uniquely identify each record.
  • Type = Alphanumeric; Private = Boolean; Rate$ = Integer; NumberGuest = Integer.
  • The query asks for Name, NumberGuest and Rate$ where NumberGuest >= 10.
SELECT Name, NumberGuest, Rate$
FROM Site1
WHERE NumberGuest >= 10;

The answer page shows example matching rows such as Bay Lodge — 10 — 1000 and Coppice Lodge — 10 — 1200.

  • Records = 20.
  • Primary key = CatNo because it is the unique identifier.
  • CatNo = Text/Alphanumeric; Title = Text/Alphanumeric; Fiction = Boolean; Price = Real.
  • For StockLevel = 0, the shown output includes BK08 — The Princess’s Story — B Penn and BK31 — Networking for Beginners — A Smith.
  • To display all titles by B Penn, use a SELECT statement with Title and a WHERE condition on Author.
SELECT CatNo, Title, Author
FROM BookList
WHERE StockLevel = 0;

SELECT Title
FROM BookList
WHERE Author = "B Penn";
  • Records = 20.
  • Primary key = CatNo because it is a unique identifier.
  • CatNo = Text; Title = Text; Genre1 = Text; Streaming = Boolean/Text as shown in the source answer.
  • The SQL asks for CatNo and Title from the 2018MOV table.
  • The condition selects records where Genre is Comedy.
SELECT CatNo, Title
FROM 2018MOV
WHERE Genre = "Comedy";
  • Fields per record = 7.
  • Primary key = Brochure No.
  • Reason: it uniquely identifies each property.
  • Garage = Boolean.
  • Number of Bedrooms = Number/Integer/Single.
  • Price in $ = Number/Single/Real/Currency.
  • Fields per record = 7.
  • Primary key = Class ID because it uniquely identifies each student record in the source table.
  • The SQL should select the student name and use a WHERE condition for Maths below 30.
  • The source question asks you to give the output produced by that SQL statement.
SELECT StudentName
FROM MARKS
WHERE Maths < 30;
  • Fields per record = 7.
  • Primary key = Element symbol.
  • The query must test Atomic number > 50.
  • It must return the state at room temperature and the name of the element, then give the matching output.
  • None of Town, Tour Date or Number of Seats can be a primary key because values can repeat and do not uniquely identify a performance.
  • Add a field such as Performance number as the primary key.
  • The reason is that the performance number uniquely identifies each performance.
  • For Number of Seats = 125, return the Town, Tour Date and Number of Seats.
SELECT Town, TourDate, NumberOfSeats
FROM THEATRETOURS
WHERE NumberOfSeats = 125;

Shown output: Algiers — 01/09/2016 — 125.

  • PCID = Text.
  • ScreenSize = Number.
  • Type = Text.
  • Price = Currency.
  • The query filters HDD(GB) so only rows with HDD(GB) = 500 are returned.
  • The shown output is LT170805 — 17 — 8 — LT — 500 — $1200.00.
SELECT PCID, ScreenSize, RAM, Type, HDD(GB), Price
FROM PCSTOCK
WHERE HDD(GB) = 500;

Activity 1: Past-paper skills sprint

Difficulty: Medium • Estimated time: 12 minutes

Choose any three of the source past-paper tables and, for each one, identify the number of fields, a suitable primary key, and one suitable data type.

  • Use the rule field = column and record = row when counting.
  • Choose the field whose values uniquely identify records.
  • Do not choose a field that contains repeated values.
  • Match each data type to the kind of value stored.

Activity 2: SQL output prediction

Difficulty: Medium • Estimated time: 15 minutes

Before looking at the answer, write down which rows would match one of the source queries (for example NumberGuest >= 10 or HDD(GB) = 500). Then compare your result with the source answer.

  • First apply the WHERE condition to each row.
  • Keep only rows that satisfy the condition.
  • Return the fields named in SELECT and keep the same column order.
  • Check the output against the source table before deciding that your answer is correct.

Check Your Understanding: Past-paper database skills

  • A field is a column and a record is a row.
  • Questions may ask separately for the number of fields and the number of records.
  • Counting the wrong direction gives the wrong answer.
  • This skill appears repeatedly in the past-paper section.
  • Do not choose a field that contains duplicate values.
  • Recognise that the existing fields cannot uniquely identify every record.
  • Create or add a new field designed to be unique.
  • Use that new unique identifier as the primary key.
  • Read the SELECT part to see which fields should be displayed.
  • Read the FROM part to identify the table.
  • Apply the WHERE condition to keep only matching rows.
  • Copy the matching field values in the required column order.
  • First select the matching rows.
  • Then sort those rows using the field named after ORDER BY.
  • Use ASC for ascending order or DESC for descending order.
  • Do not change the values themselves; only change their order.
  • A database needs each record to be uniquely identifiable.
  • The exam can test whether you recognise a genuinely unique field.
  • Repeated names, towns or categories are common distractors.
  • The correct reason should explain uniqueness, not just say “it is an ID”.

Key Takeaways

  • Database = organised collection of data; tables contain fields (columns) and records (rows).
  • Single-table/flat-file databases are the main IGCSE focus; relational databases use multiple related tables.
  • Choose field data types to match the stored data: text, character, Boolean, integer, real, date/time and currency where appropriate.
  • A primary key must uniquely identify every record; if no existing field is unique, add a suitable identifier.
  • A foreign key refers to another table’s primary key to create a relationship.
  • Validation controls what can be entered: length, format, range, type, presence, check digit and custom rules.
  • Verification checks entered data: visual check and double-entry check.
  • SQL SELECT follows SELECT → FROM → optional WHERE → optional ORDER BY.
  • Use AND when all conditions must be true; use OR when at least one condition can be true.
  • Use LIKE with % for pattern matching; * selects all columns.
  • SUM totals numeric values; COUNT counts matching rows.
  • In exam questions, show the exact requested fields and output in the correct order.

Question Bank

  • A database is an organised collection of data.
  • It organises information into tables containing fields and records.
  • It allows data to be stored and retrieved efficiently.
  • It allows data to be searched and sorted efficiently.
  • The notes state that databases are useful for large amounts of data and can be used by multiple users on remote servers.
  • A field is one piece of information about a person, item or object.
  • A field is represented by a column.
  • A record is a collection of related fields.
  • A record is represented by a row.
  • It should uniquely identify each record.
  • Its value should not repeat for different records.
  • It should provide a reliable way to locate a particular record.
  • It should support data integrity.
  • If no existing field is unique, create an additional unique field such as a performance number.
  • A length check limits the number of characters entered.
  • A format check checks that the value follows an exact pattern.
  • A range check ensures a numeric value is within an allowed range.
  • A presence check ensures a required field is not blank.
  • Validation controls what values are allowed to be entered.
  • Verification checks that entered data is correct and matches the intended information.
  • A visual check involves manually reviewing entered data.
  • A double-entry check compares two independent entries of the same data.
  • StudentID — Integer when stored as a whole-number identifier.
  • StudentName — Text/Alphanumeric.
  • Percentage — Integer if the field stores whole-number percentages.
  • DateOfBirth — Date/Time.
  • Passed — Boolean.
  • A foreign key is a field in one table that refers to a primary key in another table.
  • It provides a link between records in the two tables.
  • The primary key uniquely identifies records in the referenced table.
  • The foreign key lets related information be connected across the tables.
  • Use SELECT because the question asks to retrieve data.
  • Use * because all fields should be displayed.
  • Use FROM Customers to choose the Customers table.
  • Use WHERE Country LIKE 'U%' to find countries beginning with U.
SELECT *
FROM Customers
WHERE Country LIKE 'U%';
  • SELECT specifies the field or fields to return.
  • FROM identifies the table or tables used.
  • WHERE filters rows using a condition.
  • ORDER BY sorts the returned rows.
  • ASC sorts ascending and DESC sorts descending.
  • AND requires all connected conditions to be true.
  • OR requires at least one connected condition to be true.
  • AND therefore normally gives a more restrictive result.
  • OR can return records matching either condition.
  • SELECT Name, Maths asks for the two required fields.
  • FROM identifies the table containing the fields.
  • WHERE Maths < 30 filters the records.
  • The table name must be replaced with the actual table name in the question.
SELECT Name, Maths
FROM <table-name>
WHERE Maths < 30;
  • SUM adds the values in a specified field.
  • For example, SELECT SUM(Grade) FROM Students; calculates the total grades.
  • COUNT counts rows that meet the query criteria.
  • For example, SELECT COUNT(*) FROM Students WHERE Gender = 'Male'; counts matching male-student rows.
  • None of the three existing fields is a suitable unique primary key.
  • Repeated values mean they cannot uniquely identify a performance.
  • Add a new field such as PerformanceNumber.
  • Use the new unique field as the primary key.
  • SELECT returns Town, TourDate and NumberOfSeats.
  • FROM identifies the THEATRETOURS table.
  • WHERE tests the NumberOfSeats field.
  • The condition is NumberOfSeats = 125.
SELECT Town, TourDate, NumberOfSeats
FROM THEATRETOURS
WHERE NumberOfSeats = 125;
  • PCID — Text.
  • ScreenSize — Number.
  • Type — Text.
  • Price — Currency.
  • Read SELECT to identify the fields that must appear in the output.
  • Read FROM to identify the table containing the data.
  • Apply the WHERE condition to each record.
  • Keep only records that satisfy the condition.
  • Write the selected values in the same order as the SELECT fields and apply ORDER BY when present.