Topic 18 – Databases (Cambridge IGCSE ICT 0417)
Learning Objectives
By the end of this topic you should be able to:
- Recall the key concepts of database design and manipulation (AO1).
- Create tables, define fields, import/export data, sort, search and write simple queries (AO2).
- Use formulae and functions to perform calculations at run‑time, and evaluate the suitability of a database design (AO3).
1. Designing a Database Structure
1.1 Tables and Fields
- Table – a collection of related records (rows).
- Field – a column that stores a single type of data for each record.
1.2 Choosing Data Types
| Data type | Typical use | Example |
|---|
| Text / Short Text | Names, addresses, codes | Smith |
| Number (Integer, Decimal) | Quantities, prices, scores | 42, 3.75 |
| Date / Time | Birth dates, transaction dates | 2025‑12‑30 |
| Boolean (Yes/No) | Flags, check‑boxes | Yes |
| AutoNumber | System‑generated unique IDs | 1, 2, 3 … |
1.3 Primary Keys, Composite Keys & Foreign Keys
- Primary key (PK) – a field (or combination of fields) that uniquely identifies each record; it must be unique and not null.
- Composite primary key – when two or more fields together form a unique identifier (e.g.,
OrderID + ProductID in an Order‑Details table). - Foreign key (FK) – a field that references the primary key of another table, establishing a relationship.
- Referential integrity – the DBMS prevents orphan records by ensuring that every FK value matches an existing PK value.
1.4 Naming‑Convention Checklist
- Use a single word or camel‑case (e.g.,
CustomerID, OrderDate). - Avoid spaces and special characters.
- Prefix ID fields with the table name (
StudentID, CourseID). - Keep names short but meaningful.
1.5 Relationships, Referential Integrity & Normalisation (1NF)
- One‑to‑many – e.g. one Customer can have many Orders.
- Many‑to‑many – resolved by a junction table that contains two foreign keys.
- Referential integrity rules – cascade update/delete, restrict delete, etc.
- First Normal Form (1NF) – each field contains atomic values; no repeating groups or multiple values in a single field.
2. Manipulating Data
2.1 Import / Export
- Common formats:
.csv, .txt, .xlsx. - Use the DBMS “Import Wizard” to map each column to the correct field type.
- Export is useful for creating evidence files for the exam (e.g.,
sales.csv).
2.2 Sorting
- Single‑field sort:
ORDER BY UnitPrice ASC. - Multi‑field sort: first by
Category, then by Quantity DESC.
2.3 Searching & Query Design
2.4 Calculated (Formula) Fields
A calculated field stores an expression that is evaluated each time the record is displayed. The result is not saved permanently.
TotalPrice: [Quantity] * [UnitPrice]
In SQL‑like syntax the same calculation could be written as:
SELECT Quantity, UnitPrice, Quantity * UnitPrice AS TotalPriceFROM Sales;
3. Performing Calculations at Run‑time
3.1 Arithmetic Operators
| Operation | Formula | Example |
|---|
| Addition | FieldA + FieldB | 5 + 3 = 8 |
| Subtraction | FieldA - FieldB | 10 – 4 = 6 |
| Multiplication | FieldA * FieldB | 7 × 2 = 14 |
| Division | FieldA / FieldB | 20 ÷ 5 = 4 |
3.2 Aggregate Functions
Aggregate functions work on a set of records and return a single value.
| Function | Purpose | Syntax | Result (example data) |
|---|
| SUM() | Add all numeric values | SUM(Quantity) | 150 (30 + 45 + 75) |
| AVG() | Average of numeric values | AVG(UnitPrice) | 12.5 |
| MAX() | Highest value | MAX(TotalPrice) | 375 |
| MIN() | Lowest value | MIN(TotalPrice) | 90 |
| COUNT() | Number of records (or non‑null entries) | COUNT(*) | 5 |
3.3 Date‑Time Functions (selected)
TODAY() – returns the current date.NOW() – returns the current date and time.DATEDIFF('d', StartDate, EndDate) – number of days between two dates.- Example:
DATEDIFF('d', OrderDate, TODAY()) gives the age of an order in days.
3.4 Text Functions (selected)
LEFT(Field, n) – first n characters.RIGHT(Field, n) – last n characters.LEN(Field) – length of the text.CONCAT(Field1, Field2) or Field1 & Field2 – join two strings.- Example:
CONCAT(FirstName, " ", LastName) creates a full name field.
3.5 Combining Arithmetic with Aggregate Functions
You can embed arithmetic inside an aggregate function, e.g.:
SELECT SUM(Quantity * UnitPrice) AS GrandTotalFROM Sales;
This returns the same $100 as SUM(Total) in the example below.
3.6 Example – Sales Table
| TransactionID | Item | Quantity | UnitPrice (\$) | Total (\$) |
|---|
| 1 | Notebook | 10 | 2.50 | 25.00 |
| 2 | Pen | 25 | 0.80 | 20.00 |
| 3 | Folder | 5 | 3.20 | 16.00 |
| 4 | Marker | 12 | 1.50 | 18.00 |
| 5 | Stapler | 3 | 7.00 | 21.00 |
3.7 Using Functions on the Sales Table
- Total sales value:
SUM(Total) → 100 - Average unit price:
AVG(UnitPrice) → 3.00 - Highest transaction total:
MAX(Total) → 25 - Lowest transaction total:
MIN(Total) → 16 - Number of transactions:
COUNT(TransactionID) → 5
3.8 Common Pitfalls
- Division by zero – test the divisor before using
/. - Data‑type mismatches – arithmetic requires numeric fields; text will cause errors.
- NULL values – most aggregate functions ignore NULL, but any arithmetic expression that includes NULL returns NULL.
4. Presenting Data – Reports
4.1 Report Wizard Overview
- Select the source (table or saved query).
- Choose the fields to display. li>
- Pick a layout (columnar, tabular, justified).
- Add a Report Header (title, date, author) and a Page Footer (page number, total records).
- Finish and switch to Design view for fine‑tuning.
4.2 Formatting Essentials
- Set numeric fields to Currency or Number with two decimal places.
- Align text left, numbers right, headings centre.
- Use bold or colour to highlight totals.
4.3 Grouping & Summary Fields
- Group records by a field (e.g.,
Category) to produce a separate section for each group. - Add a Group Footer with summary functions such as
SUM([Total]) to show a subtotal for each group.
4.4 Page Layout Tips
- Portrait orientation works for most tables.
- Switch to Landscape when the report contains many columns or wide fields.
- Check “Print Preview” to avoid truncated columns.
4.5 Exporting
Use the DBMS “Export” feature to create a PDF or XPS file – essential for exam evidence.
5. Evaluation & Analysis (AO3)
During the evaluation stage of the systems life‑cycle, consider the following checklist.
- Field‑type suitability – Are numeric values stored as numbers? Are dates stored in a date field?
- Redundancy – Does any information repeat in more than one table? If so, normalise.
- Primary key choice – Is the key unique, stable and as short as possible?
- Composite keys & referential integrity – Are junction tables using composite PKs? Are cascade rules appropriate?
- Relationship design – Are one‑to‑many relationships correctly implemented with foreign keys?
- Usability – Are field names clear? Are drop‑down lists or look‑ups used where appropriate?
- Security – Are passwords required? Is sensitive data encrypted or stored in a protected table?
- Performance – Do queries run quickly? Could indexes improve speed?
- Naming conventions – Do field and table names follow the checklist in 1.4?
Write a short paragraph (≈80 words) evaluating a given design and suggest at least two improvements.
6. Safety & Security (e‑Safety)
- Use strong passwords for the database file and change them regularly.
- Back up the database to an external drive or cloud service at least once a week.
- Beware of phishing emails that ask for database passwords.
- Enable the DBMS’s built‑in encryption if confidential data are stored.
- Limit user permissions – give read‑only access where editing is not required.
7. Audience & Communication
- Documentation – Write a brief user guide for the intended audience (teacher, manager, peer). Include screenshots of forms, queries and reports.
- Copyright – Use only data that you have created or that are clearly marked as free‑to‑use. Cite any external sources.
- Email etiquette – When sending database files, describe the purpose, file size, and any required passwords.
8. File Management
| File type | Typical extension | Use |
|---|
| Microsoft Access database | .accdb / .mdb | Full‑featured relational database |
| SQLite database | .sqlite / .db | Light‑weight, portable |
| CSV (comma‑separated values) | .csv | Import / export of table data |
| Compressed archive | .zip | Required for submitting evidence files in the exam |
9. Linking to Other Syllabus Components
The same data can be used in other parts of the ICT syllabus. For example, a database can serve as the data source for a simple website (Section 21 – Website Authoring) using a server‑side script or by exporting the data to CSV and importing it into a web‑page table.
10. Quick Reference Cheat‑Sheet
| Operation | Formula / Function | Example |
|---|
| Addition | FieldA + FieldB | 5 + 3 = 8 |
| Subtraction | FieldA - FieldB | 10 - 4 = 6 |
| Multiplication | FieldA * FieldB | 7 × 2 = 14 |
| Division | FieldA / FieldB | 20 ÷ 5 = 4 |
| Sum | SUM(Field) | Σ Quantity = 150 |
| Average | AVG(Field) | AVG UnitPrice = 3.00 |
| Maximum | MAX(Field) | MAX Total = 25 |
| Minimum | MIN(Field) | MIN Total = 16 |
| Count | COUNT(Field) | COUNT TransactionID = 5 |
| Today (date) | TODAY() | Returns current date |
| Days between | DATEDIFF('d', StartDate, EndDate) | 30 days |
| Concatenate text | CONCAT(FirstName, " ", LastName) | “John Smith” |