Skip to Content
Chapter 18 · Databases — Cambridge IGCSE ICT 0417
SYLLABUS §18 Cambridge IGCSE ICT 0417 · 2026–2028

Databases

Build the structure, get the data in, ask it questions, and print the answer. Flat file or relational · data types · primary and foreign keys · relationships · forms · calculations · sorting · queries · reports — the whole of Paper 2's database block, broken down and explained.

0sub-sections: structure, manipulate, present
0data types you must set correctly
0query operators: AND OR NOT LIKE > < = ≥ ≤ ≠
0report zones: report/page header and footer
∞ ∞ 1 1 tblCustomers CustomerID PK FirstName LastName Town JoinDate Discount tblOrders OrderID PK CustomerID FK OrderDate Quantity tblBooks BookID PK Title Author Price QUERY Town = "Dhaka" AND Quantity >= 2 ∑ Total: [Qty]*[Price]
01
Where this sits

Why databases are worth a third of Paper 2

Paper 2 is 2 hours 15 minutes and 70 marks, and it tests three sections: Document Production (§17), Databases (§18) and Presentations (§19). Databases is usually the most technical of the three — and the one where a single wrong setting can quietly break everything downstream.

What the examiner is really testing

A database task in Paper 2 is a chain. You import a file, choose data types, set keys, join tables, build a form, run a query, and print a report. Each link depends on the one before it.

Chain broken at the start — a postcode stored as a number, a primary key that is not unique, two tables that were never related — and the query returns nothing and the report is empty. Most lost marks in this section are structural, not cosmetic.

That is why this chapter starts with structure and only reaches reports at the end.

The three questions every database answers

18.1 Create a database structure — what shape should the data be in, and how does it get in there?

18.2 Manipulate data — how do I calculate, sort and search it?

18.3 Present data — how do I get the answer out on paper, looking right?

The order matters You cannot query what you have not stored, and you cannot report what you cannot query. Work through this chapter in order — it follows the same order as the exam task.
Source file orders.csv / sales.txt given to you in the exam IMPORT Tables fields · data types primary & foreign keys LINK · §18.1 Form data entry radio · checkbox · dropdown ENTER · §18.1 Query & sort criteria · operators wildcards · calculated fields ASK · §18.2 Report headers footers · layout PRINT · §18.3 The Paper 2 database pipeline — break any link and everything after it fails each stage is a separate mark or group of marks in the task
Figure 1 — The database pipeline. Every Paper 2 database task follows this route, and this chapter follows it too.
02
The whole section on one page

The §18 roadmap

Everything the syllabus asks for, split into what you must be able to do and what you must know and understand. The know-and-understand points are the ones that appear as written questions.

SyllabusYou must be able to…You must know and understand…
18.1
Create a database structure
• Import data from .csv and .txt files using specified field names to create tables
• Set data types: text, numeric (integer, decimal, currency), date/time, Boolean/logical
• Set numeric sub-types: percentage, number of decimal places
• Set the display format of Boolean (yes/no, true/false, checkbox) and date/time data
• Create and edit primary and foreign keys
• Create relationships between tables
• Create and use a data entry form with specified fields, font styles and sizes, spacing between fields, character spacing, white space, radio buttons, check boxes and drop-down menus
• Types of database — characteristics, uses, advantages and disadvantages of a flat file and a relational database
• Primary and foreign keys — their characteristics
• Form design — the characteristics of good form design
18.2
Manipulate data
• Perform calculations using arithmetic operations and numeric functions — calculated fields and calculated controls
• Use formulae and functions at run time: + − × ÷, SUM, AVERAGE, MAXIMUM, MINIMUM, COUNT
• Sort data on a single criterion or on multiple criteria, ascending or descending
• Search and select data using a query on one criterion or on multiple criteria
• Search using operators: AND, OR, NOT, LIKE, >, <, =, >=, <=, <>
• Search using wildcards
No separate know-and-understand points — this sub-section is assessed through the practical task.
18.3
Present data
• Produce reports displaying all the required data and labels in full
• Use report header, report footer, page header, page footer
• Set report titles
• Produce different output layouts — tabular or columnar format, controlling the display of data and labels
• Align data and labels appropriately — right-align numeric data, decimal alignment
• Control the display format of numeric data — decimal places, currency symbol, percentage
Assessed through the printed report you produce.
One running example for the whole chapter Everything from here on uses the same business: Riverside Bookshop, which sells books to members and records each sale as an order. Using one example throughout means you can see how each setting affects the next — which is exactly how the exam task works.
03
Know and understand · types of database

Flat file and relational databases

This is the first of the three know and understand points in §18, and it is asked in almost every series: characteristics, uses, advantages and disadvantages of each.

Type 1 Flat file database

A database made of one single table. Every piece of data about every transaction is stored in that one table, and information is repeated as often as it is needed.

Characteristics: one table only · no relationships · data is repeated (redundant) · usually stored as a CSV or text file · quick to create, slow to maintain.

Uses: a simple mailing list, a single list of contacts, a small stock list, a spreadsheet used as a database, a one-off list exported from another system.

Advantages: very simple to set up and understand · no design work needed · fine for small amounts of data that rarely change · easy to export and email.

Disadvantages: data redundancy — the same facts are stored again and again · update anomalies — change one fact and you must change it in every row · insertion and deletion anomalies · wastes storage · larger chance of inconsistency · slow and unwieldy once it grows.

Type 2 Relational database

A database made of two or more linked tables. Each table stores one subject only, and the tables are connected by primary and foreign keys.

Characteristics: many tables · each table holds one entity · tables are linked by keys · each fact is stored once · relationships are one-to-one, one-to-many or many-to-many.

Uses: any system where the same customer, product or student appears many times — order processing, school records, libraries, hospitals, booking systems, stock control.

Advantages: no redundancy — each fact is stored once · no update anomalies — change a fact in one place and it is changed everywhere · data integrity is easier to enforce · less storage · faster searching · many users can work at once · one table can be changed without touching the others.

Disadvantages: takes time and skill to design properly · more complex to set up · queries must join tables together, which is slower to write and needs more knowledge · overkill for a tiny list.

The three anomalies — learn these names Update anomaly: one fact is stored in many rows, so changing it means changing every row — miss one and the data contradicts itself.
Insertion anomaly: you cannot add a new customer until they have placed an order, because the customer details only exist inside an order row.
Deletion anomaly: delete the last order for a customer and you delete the only copy of that customer's name, address and phone number as well.
FLAT FILE — one table OrderID Customer Town Total 1001Amina RahmanDhaka900.00 1002Tom BeckerChittagong320.00 1003Amina RahmanDhaka780.50 1004Sara IslamDhaka3750.00 1005Liam ChenSylhet450.00 1006Amina RahmanDhaka1920.00 ✗ Amina, Tom and Dhaka are each stored again and again ✗ Change her town and you must change 3 rows — miss one and the file says she lives in two places at once RELATIONAL — three linked tables tblCustomers CustomerIDCustomerTown C01Amina RahmanDhaka C02Tom BeckerChittagong C03Sara IslamDhaka C04Liam ChenSylhet C05Nadia HossainRajshahi tblOrders OrderIDCustomerIDTotal 1001C01900.00 1002C02320.00 1003C01780.50 1004C033750.00 1006C011920.00 1 ∞
Figure 2 — The same six orders stored two ways. On the left every fact is repeated; on the right each customer is stored once and the orders simply carry their key.

Simulation 1 — Flat file vs relational

Switch structure · then try to change one fact

Normalisation — how you get from one to the other

Normalisation is the process of taking a flat file and splitting it into linked tables so that each fact is stored once. There are formal stages (first, second and third normal form) but the exam only expects the idea:

1. Identify each entity — a real thing you store data about: customers, books, orders.

2. Give each entity its own table, with the fields that describe only it.

3. Give each table a primary key.

4. Put a copy of that primary key into any table that needs to refer to it — that copy is the foreign key.

5. Create the relationship between them.

How the question is usually phrased

Q · 4 marks "Explain the difference between a flat file database and a relational database."

A flat file stores all the data in one table, so information is repeated in many rows. A relational database stores the data in two or more linked tables, each holding one entity, joined by primary and foreign keys. This means each fact is stored once in a relational database, so it is easier to update and there is less redundancy, but the database takes longer to design.

Weak answer — 1 of 4 "A relational database has more than one table." True, but it only scores one mark. Add why it has more than one table (to remove redundancy), how they are joined (keys), and the consequence (each fact stored once, easier to update).
04
§18.1 · structure

Tables, fields, records — and importing the data

Before you can set a data type or a key, you need a table. In the exam you do not type the data in — you are given a .csv or .txt file and you import it.

The three words you must not mix up

Entity — a real thing you store data about: a customer, a book, an order.

Table — where the data about one entity is stored. One entity, one table.

Field — one column. One piece of information about the entity: Town, Price, OrderDate.

Record — one row. All the fields for one single customer, book or order.

"Field" and "column" mean the same thing; "record" and "row" mean the same thing. Use the exam's word: field and record.

Naming fields well

Field names must be meaningful — someone reading the report should understand them.

The task will often specify the field names to use. Use them exactly: if it says DateOfBirth, do not type DOB.

Avoid spaces in field names — use OrderDate or Order_Date instead. Spaces force you to wrap the name in square brackets in every formula.

Do not put the unit in the field name (PriceInTaka) — put it in the report label instead.

The two file types you will be given

.csv — comma separated values. Plain text, one record per line, with a comma between each field. The first line often holds the field names.

.txt — plain text. The values may be separated by commas, tabs, or be at fixed widths.

Both are flat files: a single list of records with no relationships. Your job in the exam is often to import one and then split it into linked tables.

1 · The source file OrderID,OrderDate,CustName,Town,Price,Qty 1001,2024-03-02,Amina,Dhaka,450,2 1002,2024-03-04,Tom,Chittagong,320,1 1003,2024-03-07,Amina,Dhaka,780.5,1 1004,2024-03-11,Sara,Dhaka,1250,3 commas separate the fields the first line names them orders.csv , import 2 · The import wizard Delimited or fixed width? ● Delimited ○ Fixed width Which delimiter? ● Comma ○ Tab ○ Semicolon First row contains field names? ☑ Yes Set each field's data type → four questions, four chances to lose marks 3 · The table OrderID OrderDate Town 100102/03/2024Dhaka 100204/03/2024Chittagong 100307/03/2024Dhaka 100411/03/2024Dhaka tblOrders — then set the primary key
Figure 3 — Importing a .csv file. The wizard asks four things; get any of them wrong and every field lands in the wrong column or the wrong type.

The four import traps

1 · Wrong delimiter. Choose tab when the file uses commas and every record imports as one giant field. Look at the preview pane before clicking Finish.

2 · "First row contains field names" left off. The heading line imports as a record of data, so OrderID ends up sitting in the table as if it were an order.

3 · Numbers and dates landing as text. The wizard guesses; check the preview and set the type yourself. This is why the next section matters so much.

4 · No primary key set. Either let the wizard add one, or choose the field that is unique. Without it you cannot build relationships later.

Dates: the one that catches everyone out

A date in a text file can be 2024-03-02, 02/03/2024 or 3/2/24. The database reads it using your computer's regional settings.

If your machine is set to US format (mm/dd/yyyy), then 05/03/2024 means 5 March to you but 3 May to the database. Anything after the 12th of the month cannot be a month, so those dates import correctly — which is exactly why the error hides until it is too late.

Exam habit After importing, open the table and check the first and last date. If the day and month have swapped, re-import and set the date format explicitly.
05
§18.1 · structure

Data types

The syllabus lists five types — text, numeric, date/time, Boolean/logical — with numeric split into integer, decimal and currency, plus the percentage sub-type and display formats for Boolean and date/time. Choosing the wrong one is the commonest structural error in Paper 2.

Data typeStoresSet it forWhy it matters
Text
(short text, long text / memo)
Letters, digits and symbols treated as characters Names, addresses, postcodes, phone numbers, ID codes, descriptions, anything you will never add up Keeps leading zeros (01712…, DH-1207). But text sorts character by character, so "10" comes before "9".
Integer
numeric sub-type
Whole numbers only, positive or negative Quantities, counts, ages, stock levels, anything that can never have a decimal part Uses less storage and calculates faster. Any decimal part is rounded or lost.
Decimal
numeric sub-type
Numbers with a decimal part Measurements, weights, distances, marks, averages You control the number of decimal places — the stored value keeps full precision, only the display is rounded.
Currency
numeric sub-type
Money values with a fixed number of decimal places Prices, totals, salaries, payments Never suffers from rounding drift the way floating-point numbers can, and displays a currency symbol and thousands separator.
Percentage
numeric sub-type
A number shown as a fraction of 100 Discount rates, interest rates, attendance, exam marks as percentages Important: the stored value is usually the decimal (0.15) and the display shows 15% — know which one your software expects.
Date/Time A date, a time, or both Order dates, dates of birth, appointment times, deadlines Lets you sort chronologically, filter by month or year, and do date arithmetic (days between two dates). The display format is chosen separately.
Boolean / Logical One of two values only Member?, Paid?, In stock?, Discount applied?, Over 18? Only two states are possible, so invalid data cannot be entered. Display as Yes/No, True/False or a checkbox.
The rule that answers most exam questions Ask: "will I ever do arithmetic on this?" If the answer is no, it is text — even if it is made of digits. A postcode, a phone number, a national ID and a product code are all text. You never add two phone numbers together, and you must not lose the leading zero.

Simulation 2 — The data type lab

Pick a field · try the wrong type on purpose
✓ Correct type for this field.
How the data is stored and displayed
Sorted with this type
06
Know and understand · §18.1

Primary keys and foreign keys

The second know and understand point: the characteristics of primary and foreign keys. Keys are what turn a pile of tables into a relational database — without them there are no relationships, and without relationships there is nothing to query across.

Key 1 Primary key

The field (or set of fields) that uniquely identifies each record in a table. No two records may share the same primary key value.

Its characteristics — learn these four:

1 · Unique. No two records can have the same value. This is the whole point.

2 · Never empty. Every record must have a value — a blank primary key would identify nothing.

3 · Does not change. A primary key must be stable for the life of the record. If it changes, every foreign key that refers to it breaks.

4 · Minimal. Use the smallest set of fields that does the job. One field is better than two.

Composite key — sometimes no single field is unique, so two fields together form the key. In tblBooks, Title alone is not unique (the same title can be reprinted), and neither is Author. Title + Author together usually works.

AutoNumber — most packages can generate the key for you (1, 2, 3…). This guarantees uniqueness and means nobody has to invent a code.

Key 2 Foreign key

A field in one table that holds the primary key of another table. It is the link between the two tables.

Its characteristics — learn these four:

1 · It is not unique. Unlike a primary key, the same foreign key value appears many times. Customer C01 appears in three orders — that is exactly what makes it a one-to-many relationship.

2 · It matches the primary key's data type. A text CustomerID cannot link to a numeric one.

3 · Every value must exist in the parent table. This rule is called referential integrity — you cannot have an order for a customer who does not exist.

4 · It may be left empty if the relationship is optional — an order that has not yet been assigned to a customer.

Why not use names as keys? Because a name is not guaranteed to be unique (two Amins), and names change. A customer ID does neither.

The one-sentence version A primary key identifies a record uniquely inside its own table. A foreign key is a copy of that primary key placed in another table to create the link. The primary key is always on the one side of the relationship; the foreign key is always on the many side.
tblCustomers CustomerID FirstName Town C01AminaDhaka C02TomChittagong C03SaraDhaka C04LiamSylhet C05NadiaRajshahi tblOrders OrderID CustomerID Qty 1001C012 1002C021 1003C011 1004C033 1005C041 1008C016 1 ∞ PRIMARY KEY — every value is different, none is blank, none ever changes C01 identifies one customer and one customer only FOREIGN KEY — C01 appears three times, and that is correct every value here must already exist in the primary key column
Figure 4 — The same field name on both sides, doing two different jobs. On the left it is the primary key and must be unique; on the right it is the foreign key and is expected to repeat.

Simulation 3 — The primary key lab

Which field could be the primary key? Test them
tblCustomers — click a field to nominate it
Click a field name to test whether it could be the primary key.
The table
07
§18.1 · structure

Creating relationships between tables

Once each table has a primary key and the child tables carry the matching foreign key, you create the relationship. Until you do, the database does not know the tables are connected, and a query cannot pull data from both.

One-to-many (1 : ∞)

By far the most common. One record in the first table relates to many records in the second — and every record in the second relates to only one in the first.

Example: one customer places many orders; each order belongs to one customer.

How it is built: the primary key of the "one" table is placed into the "many" table as a foreign key. There is no other way to build it.

One-to-one (1 : 1)

One record in the first table relates to exactly one record in the second.

Example: each employee has one payroll record; each student has one medical record.

Why bother? To split a very wide table for security or speed — the sensitive fields go in a separate table that fewer people can open. It is used rarely.

Many-to-many (∞ : ∞)

Many records in the first table relate to many in the second.

Example: many students take many courses; many books are written by many authors.

A relational database cannot store this directly. You must break it into two one-to-many relationships using a link table (also called a junction table) in the middle, holding the two foreign keys.

Referential integrity Referential integrity is the rule that every foreign key value must have a matching primary key value in the parent table. Switch it on when you create the relationship and the database will refuse an order for a customer who does not exist, and will stop you deleting a customer who still has orders. That is what keeps a relational database consistent — and it is a mark in most Paper 2 tasks.

Simulation 4 — The relationships lab

Click the field on the ONE side, then the field on the MANY side
08
§18.1 · structure

Creating and using a data entry form

A form is a window for entering, editing and viewing data one record at a time. In Paper 2 you will nearly always be asked to create one, and to get the controls right.

Why use a form instead of typing into the table?

One record at a time. Far less chance of typing a value into the wrong row.

Controls restrict what can be entered. A drop-down cannot be misspelled; a checkbox can only be true or false. This is the main reason forms exist — they prevent invalid data.

Validation can be added — a rule that rejects an impossible date or an empty required field.

It can show data from several tables at once, including a subform listing that customer's orders.

Labels and layout make the data understandable to someone who does not know the table design — which is who will be using it.

The four controls the syllabus names

ControlUse it whenExample
Text boxThe value is free text or a number the user typesFirstName, Town, JoinDate, Quantity
Radio buttonsThere are a few fixed options and only one may be chosenMembership type: Standard ● Student ● Premium
Check boxA Boolean field — yes or no, true or falseDiscount? Member? Paid?
Drop-down menu
(combo box)
There is a long list of fixed options, or the list comes from another tableTown picked from tblTowns; BookID picked from tblBooks
Choosing between them Radio buttons for few options, drop-down for many. A drop-down with only two options is harder to use than two radio buttons — you have to click twice to see the choice.

The layout settings the syllabus lists

Specified fields — include every field the task names, and no others. A missing field loses a mark even if the form looks beautiful.

Font styles and sizes — choose one font and one size and use them consistently. Headings may be larger or bold; body fields must match each other.

Spacing between fields — enough vertical space that the eye can follow from one field to the next without them merging into a block.

Character spacing of individual fields — the space between the letters inside a field. Widening it on a short code field (a customer ID, a postcode) makes the value much easier to read and to check.

Use of white space — empty space around and between groups of fields. It is not wasted space; it is what makes the form scannable.

The three regions of a form

Form header — appears once at the top. Holds the title of the form, and sometimes a logo or instructions.

Detail — the middle. Holds the labels and controls, and repeats once per record.

Form footer — appears once at the bottom. Holds totals, buttons, or the date the form was printed.

Do not confuse these with report headers and footers — a report has four zones (report/page header and footer) because it prints many records over several pages. A form shows one record, so it has three.

Simulation 5 — The form designer

Change the layout and controls · watch the design score
14 px
14 px
1.0 px
18 px
✓ Good design.
Form preview — one record at a time
Good design scorecard
09
Know and understand · §18.1

Characteristics of good form design

The third and last know and understand point in §18.1. It is usually asked as a "describe the characteristics of a well-designed form" question — and it is also exactly what the practical task marks.

Content

All required fields are present, with no unnecessary ones. A form that cannot capture the data is useless however pretty it is.

Every field has a clear label. Not Txt3 — "First name". The label must say plainly what goes in the box.

Labels are meaningful to the user, not to the designer. "Date joined", not JoinDate.

The correct control is used for each field — checkbox for yes/no, radio for a short fixed list, drop-down for a long one, text box only for genuinely free text.

Choices are restricted wherever possible, so invalid data cannot be typed in at all.

Validation is applied — required fields cannot be left empty, dates must be real dates, numbers must be numbers.

Layout

A clear title in the form header, so the user knows what they are filling in.

Logical order and grouping — fields follow the order the user thinks in, and related fields sit together (all the name fields, then all the address fields).

Consistent font style and size throughout the detail area.

Labels aligned with each other and controls aligned with each other, usually left-aligned labels with the boxes starting at the same x-position down the form.

Adequate spacing between fields, so each field reads as a separate item.

Generous white space — the form must not look cramped. Empty space is a design tool, not wasted paper.

A sensible tab order, so pressing Tab moves down the form in the order the user expects.

✗ POORLY DESIGNED data entry Txt1 Txt2 Txt3 Disc Twn Dt Mmbr ← meaningless labels ← everything a text box: free typing means spelling errors ← no title, no grouping ← only 8 px between fields ← no white space, all pushed into the top-left corner three fonts, three sizes tiring to use · produces bad data ✓ WELL DESIGNED Riverside Bookshop — Member Details Customer ID First name Last name Town Date joined Discount? C 0 1 Dhaka ▾ ✓ clear labels, all aligned consistent font and size drop-down: no misspellings check box for a yes/no field 36 px between fields · white space
Figure 5 — The same form, designed badly and designed well. The right-hand version cannot accept a misspelled town, a nonsense date or a half-answer to a yes/no question.
10
§18.2 · manipulate data

Performing calculations

A database stores facts and then works things out from them. The syllabus wants you to use arithmetic operators and numeric functions, in calculated fields and calculated controls, performed at run time.

Idea 1 Calculated field

A field whose value is worked out from other fields rather than typed in. It is defined by an expression and it produces one value per record.

Example: tblOrders stores Quantity and the book's Price. A calculated field named Total with the expression

Total: [Quantity] * [Price]

gives each order its own line total. A calculated field is a column — one value on every row.

Never store what you can calculate. If you stored the total as well, it would go out of date the moment somebody changed the quantity.

Idea 2 Calculated control

A box on a form or report that displays the result of a calculation. It is not a field in a table — it lives on the form or report itself.

Example: a box in the report footer containing

=Sum([Total])

shows the grand total once, at the end of the report. A calculated control usually produces one value for the whole set, because it uses an aggregate function.

Where they go: totals and counts go in the report footer or form footer, not in the detail area — otherwise they repeat on every single row.

FunctionWhat it returnsExample expression and result
SUMThe total of all the values=Sum([Total]) → 12,463.00 — all eight orders added together
AVERAGE (AVG)The mean — the total divided by how many there are=Avg([Total]) → 1,557.88 — the average order value
MAXIMUM (MAX)The largest value=Max([Total]) → 3,750.00 — the biggest single order
MINIMUM (MIN)The smallest value=Min([Total]) → 320.00 — the smallest single order
COUNTHow many records there are=Count([OrderID]) → 8 — eight orders were placed
"At run time" — what the syllabus means The calculation is performed every time the query, form or report is opened, not once when you create it. So the moment a new order is added, the total changes; the moment a price is edited, every line total updates. That is why you never store a value you could have calculated — a stored value goes stale, a run-time calculation cannot.
Two traps 1 · COUNT counts records, not values. =Count([Quantity]) tells you how many orders there are (8), not how many books were sold (20). Add them up with SUM instead.
2 · Division by zero. [Total] / [Quantity] fails the moment a quantity is zero. Guard it, or filter those records out first.

Simulation 6 — The calculations lab

Build the calculated field · then aggregate it
✓ A line total multiplies quantity by unit price.
Aggregate function
Calculated control in the report footer
Tk 12,463.00
=Sum([Total])
11
§18.2 · manipulate data

Sorting data

Sorting puts records into order. On its own it is easy — but the syllabus asks for multiple criteria, and that is where candidates lose marks by not realising that the order of the sort fields matters.

Ascending and descending

Ascending (ASC) — the smallest or earliest first: A→Z, 0→9, oldest date → newest date.

Descending (DESC) — the largest or latest first: Z→A, 9→0, newest date → oldest date.

Descending is how you find the biggest seller, the highest mark or the most recent order — sort descending and the answer is the first record.

Each field sorts by its own rules: text sorts alphabetically character by character, numbers sort by value, dates sort chronologically. This is exactly why setting the right data type matters — text "sorts" 10 before 9.

Single criterion sorting

One field, one direction. "Sort the data into ascending order of Town."

Sorting does not change the stored order of the records in the table — it only changes the order in which they are displayed by the query, form or report. The underlying data is untouched.

Because of that, the same table can be shown in several different orders at once, by several different queries.

Multiple criteria — the bit that is examined With two sort fields, the database sorts by the first field, and only uses the second to break ties inside each group of equal first-field values. It never re-sorts the whole list by the second field.

So Town ascending, then Customer descending lists the towns A→Z, and inside Dhaka the customers Z→A. But Customer ascending, then Town descending gives a completely different list. Change the order of the sort fields and you change the answer.
Sort 1 — Town ascending, then Customer the towns run A→Z; the second field only orders names inside each town TownCustomerQty ChittagongTom Becker1 ChittagongTom Becker4 DhakaAmina Rahman2 DhakaAmina Rahman6 DhakaSara Islam3 RajshahiNadia Hossain2 SylhetLiam Chen1 1st = Town  ·  2nd = Customer (tie-break only) Sort 2 — Customer ascending, then Town swap the order of the same two fields and the whole list changes CustomerTownQty Amina RahmanDhaka2 Amina RahmanDhaka1 Amina RahmanDhaka6 Liam ChenSylhet1 Nadia HossainRajshahi2 Sara IslamDhaka3 Tom BeckerChittagong4 1st = Customer  ·  2nd = Town (tie-break only)
Figure 6 — The same two fields, sorted in a different order. The first field drives the list; the second only breaks ties inside it.

Simulation 7 — The sorting lab

Add sort levels · then swap their order
12
§18.2 · manipulate data

Searching and selecting: queries, operators and wildcards

A query is a question you ask the database. It selects the subset of records that match your criteria, and that subset is what you then sort, report on or print.

What a query actually is

A query is saved criteria, not saved data. Run it and the database looks at the current table and returns the matching rows. Add a new order tomorrow and the same query will include it.

A criterion is the test a record must pass: Town = "Dhaka". Records that pass are selected; the rest are hidden.

Multiple criteria means two or more tests joined by AND or OR.

Queries are built in the query design grid (query by example, or QBE): you add the fields you want to see, then type the criteria underneath.

The nine operators

OperatorMeansExample
=equal to= "Dhaka"
<>not equal to<> "Dhaka"
>greater than> 2
<less than< 500
>=greater than or equal to>= 2
<=less than or equal to<= 500
LIKEmatches a pattern, used with wildcardsLIKE "D*"
ANDboth tests must be true= "Dhaka" AND >= 2
OReither test may be true= "Dhaka" OR = "Sylhet"

NOT is the tenth: it reverses a test, so NOT "Dhaka" means everything except Dhaka — the same result as <> "Dhaka".

AND narrows · OR widens · NOT inverts Adding an AND condition can only ever give you the same or fewer records — every record now has to pass two tests. Adding an OR condition can only ever give you the same or more records — a record only has to pass one of them. "Show me orders from Dhaka AND Sylhet" is a nonsense question that returns nothing — no single order can be from both towns. The question you meant was OR. This is the single commonest query error in Paper 2.

Wildcards

A wildcard is a character that stands in for other characters, used with LIKE when you do not know the exact value.

* — any number of characters, including none at all.
LIKE "D*" finds Dhaka and Dinajpur.
LIKE "*pur*" finds anything containing "pur" anywhere.

? — exactly one character.
LIKE "B0?" finds B01 and B05, but not B011.

# — exactly one digit (in some packages).
LIKE "B0#" finds B01 but not B0A.

The QBE grid

The query design grid has one row per setting and one column per field:

Field — the fields to include in the result.
Table — which table each field comes from.
Sort — ascending or descending.
Show — ticked if the field appears in the output.
Criteria — the first test.
or — a second test joined with OR.

Two criteria on the same row = AND. A criterion on the or row = OR. That single rule is how you build every multi-criteria query.

Simulation 8 — The query lab

Build criteria · try AND, OR, NOT and wildcards
8 records match
13
§18.3 · present data

Reports: headers, footers and layouts

A report is the printed answer. It takes the records a query selected, arranges them, and adds the headings, totals and page numbers that make them readable on paper.

Riverside Bookshop — Orders report header · printed ONCE, on page 1 only OrderID Date Customer Total 1001 02/03/2024 Amina Rahman 900.00 1002 04/03/2024 Tom Becker 320.00 1003 07/03/2024 Amina Rahman 780.50 1004 11/03/2024 Sara Islam 3,750.00 1005 14/03/2024 Liam Chen 450.00 1006 18/03/2024 Nadia Hossain 1,220.50 1007 22/03/2024 Tom Becker 3,122.00 1008 25/03/2024 Amina Rahman 1,920.00 Prepared 26/03/2024 Page 1 of 2 Grand total 12,463.00 REPORT HEADER once, at the very start PAGE HEADER on EVERY page — column headings DETAIL the records themselves PAGE FOOTER on EVERY page — page number, date REPORT FOOTER once, at the very end — totals, counts, averages The five zones of a database report
Figure 7 — Where each zone prints. Two zones appear once (report header and footer); two appear on every page (page header and footer); the detail holds the records.

Report header and report footer — once

Report header prints once, at the very beginning of the report. It holds the report title, the business name, a logo, and the date the report was produced.

Report footer prints once, at the very end. It holds the grand totals and counts — the =Sum([Total]) calculated controls from §10.

The test: if it should appear on page 1 only, or on the last page only, it belongs in a report header or footer.

Page header and page footer — every page

Page header prints at the top of every page. It holds the column headings — without it, pages 2, 3 and 4 are just columns of numbers with no idea what they mean.

Page footer prints at the bottom of every page. It holds the page number ("Page 2 of 5"), the date, and often the candidate's centre and candidate number — which Paper 2 requires on every printed page.

The test: if a reader holding only page 3 needs it, it belongs in a page header or footer.

Tabular layout

One row per record, one column per field, with the column headings across the top — it looks like a table.

Use it when you have many records with few fields each, and the reader wants to compare or scan down a column. This is the layout for an order list, a stock list or a mark sheet.

It fits far more records on a page, which saves paper.

Columnar layout

Each record is a block, with the labels down the left and the values beside them — like a filled-in form.

Use it when each record has many fields, or fields with long values (an address, a description) that would not fit in a narrow column. This is the layout for a customer record, a patient record or an invoice.

It is far easier to read one complete record, but it uses much more paper.

"Displaying all the required data and labels in full" This phrase is in the syllabus and it is a mark. It means nothing may be cut off. If a column is too narrow, the database prints The River's Ed… or ##### instead of the value. Widen the control, shorten the label, or switch to a columnar layout. After producing any report in Paper 2, look down every column and check the longest value is completely visible.

Simulation 9 — The report designer

Switch zones and layout · watch what prints where
Zones
Layout
✓ All four zones present.
Print preview
14
§18.3 · present data

Display formats and alignment

The last bullet of §18: control the display format of numeric data, and align data and labels appropriately. Small settings, but they are what makes a report look professional — and they are checked in every Paper 2 mark scheme.

Setting Number of decimal places

How many digits are shown after the decimal point. Display only — the stored value keeps full precision, so totals still add up exactly.

0 dp — counts, quantities, whole units: 450.

2 dp — money in nearly every currency: 450.00. Money always shows exactly two decimal places, even when they are both zero.

1 or 3 dp — measurements and scientific data: 12.5 kg, 3.142 m.

Consistency is the rule. Every money figure in the report must use the same number of decimal places. A column showing 450.00, 320 and 780.5 looks careless and loses a mark.

Setting Currency symbol and percentage

Currency adds the symbol and usually a thousands separator: Tk 12,463.00, $1,250.00. Set it once on the field or control, not by typing the symbol into the label.

Why thousands separators matter: 1246300 takes a moment to read; 1,246,300 does not.

Percentage shows the value as a fraction of 100, with the % sign: 12.5%. Be clear which you have stored — most packages store 0.125 and display 12.5%; some expect you to type 12.5. Check, or every figure in the report will be 100 times too small.

Alignment Right-align numeric data

Text is left-aligned. The eye reads from the left edge, so a ragged right edge is fine for words.

Numbers are right-aligned. The units column must line up, so that the size of a number can be judged at a glance by where its last digit sits. Left-align a column of money and 320.00, 1250.00 and 78.50 all start in the same place — the reader has to count digits to compare them.

Column headings are aligned with the data beneath them: a right-aligned column of numbers gets a right-aligned heading.

Alignment Decimal alignment

Decimal alignment lines the column up on the decimal point itself — the whole numbers sit to the left of it and the decimal places to the right.

It is the same idea as the decimal tab stop in a word processor, and it is the correct alignment whenever values have different numbers of digits before the point.

With a fixed number of decimal places, right alignment and decimal alignment give the same result — which is why setting 2 decimal places and right-aligning is the standard combination for money.

Never centre a column of numbers. Centring destroys the units alignment entirely.

Simulation 10 — The format and alignment lab

Compare the raw column with the formatted one
2
Alignment
✓ Right-aligned numeric data with 2 decimal places.
Report column — before and after
15
Paper 2 · how §18 is actually asked

Exam guidance, model answers and worked tasks

Databases carry a large share of Paper 2's 70 marks. Nearly all of it is practical — but the three know and understand points are examined in writing, and those are the ones candidates under-answer.

The command words

WordWhat it demandsMarks
StateShort, factual. No reasoning.1–2
IdentifyPick the right item from those given.1
DescribeSay what it is and what you would see.2–3
ExplainGive the reason — say why. Highest value.2–4
CompareGive similarities and differences, for both things.3–6

"Compare a flat file with a relational database" is a Compare question. Half the marks are for the flat file, half for the relational — an answer that only describes one of them cannot score more than half, however good it is.

Model answer — flat file vs relational

Q · 6 marks "Compare a flat file database with a relational database."

A flat file database stores all of its data in one table, whereas a relational database stores its data in two or more related tables.
In a flat file the same data is repeated in many records, so there is a lot of redundancy and the file is larger; in a relational database each fact is stored once, so there is far less redundancy.
In a flat file, changing one fact means changing it in every record where it appears, which can lead to inconsistency; in a relational database it is changed in one place.
A flat file is simple and quick to set up; a relational database takes longer to design and needs more skill, and queries have to join the tables together.

Weak answer — 2 of 6 "A flat file has one table and a relational has more than one." Correct, but it is one point. A 6-mark Compare expects three or four developed points covering both.

Model answer — primary and foreign keys

Q · 4 marks "Describe the characteristics of a primary key and a foreign key."

A primary key is a field that uniquely identifies each record in a table. Its value must be unique, it must never be empty, and it should not change over time. Two fields together can form a composite key if no single field is unique.
A foreign key is a field in one table that holds the primary key of another table. Unlike a primary key, its values are not unique — the same value appears in many records. It is what links the two tables together, and with referential integrity switched on, every foreign key value must have a matching primary key value.

Model answer — good form design

Q · 4 marks "Describe the characteristics of a well-designed data entry form."

It has a clear title and includes all the required fields, each with a meaningful label. The fields are in a logical order with related fields grouped together.
The font style and size are consistent, labels and controls are aligned with each other, there is enough spacing between fields and plenty of white space, so it does not look cramped.
The correct control is used for each field — check box for yes/no, radio buttons for a short fixed list, drop-down for a long one — so that invalid data cannot be entered.

Worked Paper 2 tasks

Four typical database tasks, broken down the way a top-scoring candidate works through them.

Task A Import and set up

"Import the data in orders.csv into a new table called tblOrders using the field names given."

1. Choose Import, browse to the file, and pick delimited.

2. Set the delimiter to comma — check the preview shows separate columns.

3. Tick "first row contains field names".

4. Set each field's data type in the wizard: ID → text or integer, date → date/time, money → currency.

5. Choose a primary key — let the wizard add one, or pick the unique field.

6. Name the table exactly as asked: tblOrders.

The classic error: clicking Finish before checking the preview, so the whole file lands in one column.

Task B Link the tables

"Create a one-to-many relationship between tblCustomers and tblOrders."

1. Open the Relationships window and add both tables.

2. Check that CustomerID is the primary key of tblCustomers and that tblOrders contains a CustomerID field of the same data type.

3. Drag CustomerID from tblCustomers onto CustomerID in tblOrders.

4. In the dialog, tick Enforce Referential Integrity.

5. Confirm the relationship type is One-To-Many, then Create.

The classic error: forgetting referential integrity, or dragging the wrong way round — always drag from the one side to the many side.

Task C Build the query

"Select all orders from Dhaka or Sylhet where the quantity is more than 2."

1. Read the question carefully: two towns = OR; more than 2 = > 2 (not >=).

2. Add the fields you need to the grid: OrderID, Town, Quantity, Total.

3. Under Town, type "Dhaka" on the criteria row and "Sylhet" on the or row — the or row is what makes it OR.

4. Under Quantity, type >2 on the criteria row — the same row as the first town, so it is joined with AND.

5. Run it and count the records to check the answer looks sensible.

The classic error: putting both towns on the criteria row — which asks for an order that is from Dhaka AND Sylhet, and returns nothing.

Task D Produce the report

"Produce a report showing all the selected orders with a title, column headings, page numbers and a grand total."

1. Base the report on the query from Task C, not on the raw table.

2. Report header — add the title.

3. Page header — move or retype the column headings here so they repeat on every page.

4. Page footer — add ="Page " & [Page] & " of " & [Pages] and your centre and candidate number.

5. Report footer — add a calculated control =Sum([Total]).

6. Right-align the money column, set it to 2 decimal places with the currency symbol, and widen every control until nothing is cut off.

The classic error: leaving the column headings in the report header, so they print once and pages 2+ have none.

The twelve errors that cost the most marks

#The mistakeDo this instead
1Wrong delimiter, or "first row contains field names" left offCheck the preview pane before clicking Finish
2Storing a postcode or phone number as a numberText — you never add them up, and leading zeros matter
3Storing money as plain decimalCurrency, 2 decimal places, with the symbol
4Choosing a primary key that is not uniqueTest it: if any value repeats, it cannot be the key
5Tables that were never relatedOpen the Relationships window and drag PK → FK
6Referential integrity left offTick it — it is usually a mark in its own right
7Using a text box for a yes/no fieldCheck box — it makes wrong data impossible
8Storing a value that could have been calculatedUse a calculated field — it cannot go stale
9COUNT when you meant SUMCOUNT counts records; SUM adds values
10AND when you meant ORAND narrows, OR widens — "Dhaka AND Sylhet" returns nothing
11Column headings left in the report headerMove them to the page header so they repeat
12Data cut off in the reportWiden the control and check the longest value is fully visible
16
Test yourself

Chapter 18 quick quiz

Sixteen questions covering every bullet of §18. Answer them all, then check — each one explains itself.

0 / 16 Nothing answered yet — pick an option to see the feedback.
0 / 16

17
Before the exam

The §18 checklist

Everything in this chapter on one page. Tick it off honestly.

0 / 32 Nothing ticked yet. Work down the list honestly — anything you cannot do, go back and read that section.

Structure — I can…

Forms — I can…

Manipulate data — I can…

Present data — I can…

Where §18 fits

§18 shares Paper 2 with §17 and §19, and it leans on earlier sections:

§4–8 Data and files — data types, validation and file formats appear in both theory and practical work.

§14 Styles — the report formatting settings are the same ideas applied in a different application.

§16 Graphs and charts — a chart can be embedded in a database report, and the same rules about axes, labels and legends apply.

§17 Document production — headers, footers, page numbering and alignment in a report work exactly as they do in a word-processed document. Learn them once.

§20 Spreadsheets — SUM, AVERAGE, MAX, MIN and COUNT are the same five functions in both applications, with the same syntax.

The one-paragraph summary

Decide first whether the data is flat (one table, repeated data, update anomalies) or relational (linked tables, each fact stored once, needs designing). Import the source .csv or .txt file, watching the delimiter and the field-name row. Give every field the right data type — text for codes, numeric for anything you add up, date/time for dates, Boolean for yes/no — and set its display format. Give each table a unique, never-empty primary key, copy it into the child table as a foreign key, and create the relationship with referential integrity on. Build a form with the right controls so bad data cannot be typed in. Then ask questions: calculate with a calculated field, sort on one or many fields, and query with operators and wildcards, remembering that AND narrows and OR widens. Finally print a report: title in the report header, column headings in the page header, page numbers in the page footer, grand total in the report footer, numbers right-aligned with two decimal places — and nothing cut off.

Chapter 18 · Databases — Cambridge IGCSE Information & Communication Technology 0417
Syllabus version 3 (December 2025) · for examinations in 2026, 2027 and 2028 · Section 18