Wimzee Cambridge Academy
← All Revision Notes← IGCSE Computer Science

Databases

Revision Notes — IGCSE
CAIE IGCSE Computer Science (0478) • Topic 9 of 10 • Paper 1 & Paper 2
Mastered: 0 / 2

9.1 Database Structure

A database is an organised collection of related data that can be searched, sorted and updated quickly. A database management system (DBMS) is the software that creates and controls the database, provides the user interface, enforces validation and access rights, and allows queries to be run.

TermMeaning
Table / fileA collection of related records, e.g. Students
RecordOne complete row — all the data about one person or item
FieldOne column — a single attribute, e.g. Surname
Primary keyA field that uniquely identifies each record; it cannot be duplicated or left empty
Foreign keyA field in one table that links to the primary key of another table
Data dictionaryA description of every field: name, data type, length, validation rules

9.2 Flat File and Relational Databases

Flat fileRelational
StructureOne single tableTwo or more linked tables
RedundancyData is repeated in many recordsData is stored once and linked by keys
ProblemsWasted storage, inconsistency when a repeated value is updated in one place only, harder to maintainMore complex to design, but consistent and easier to update
ExampleA single table holding student name, class and teacher for every rowStudents table + Classes table linked by ClassID

Splitting data into related tables removes redundancy (the same data stored many times) and prevents inconsistency (the same data stored with different values in different places).

9.3 Data Types and Validation

Data typeUse
Text / alphanumericNames, addresses, postcodes
Number (integer / real)Age, price, quantity
Date / timeDate of birth, appointment time
BooleanYes/no fields such as Paid
CurrencyMoney values

Validation rules on a field include: range check (e.g. 0–100), length check (exactly 8 characters), presence check (must be filled in), type check (must be a number), format check (e.g. DD/MM/YYYY) and lookup check (must be one of a list of values).

9.4 SQL

SQL (structured query language) is used to search and manipulate data in a relational database.

SELECT field1, field2 FROM table WHERE condition ORDER BY field ASC|DESC GROUP BY field
ClausePurpose
SELECTWhich fields to display (* for all)
FROMWhich table(s) to use
WHEREWhich records to include
ORDER BYSort the results (ASC or DESC)
GROUP BYGroup records so totals can be calculated per group
SELECT Surname, Mark FROM Students WHERE Mark >= 50 AND Class = "10A" ORDER BY Mark DESC SELECT Class, AVG(Mark) FROM Students GROUP BY Class SELECT COUNT(*) FROM Students WHERE Mark < 40
FunctionReturns
COUNTThe number of records
SUMThe total of a numeric field
AVGThe average of a numeric field
MAX / MINThe largest / smallest value

Exam trap

Text values in SQL need quotation marks (WHERE Class = "10A"); numbers do not. Forgetting the quotes, or using = instead of AND for two conditions, are the most common SQL errors.

Five-minute drill

  1. Define primary key and foreign key.
  2. Give two problems caused by storing data in a flat file.
  3. Write an SQL query to list all students with a mark above 80, highest first.
  4. Name three validation checks and an example of each.
  5. State two functions of a DBMS.
Exam practice 1[4]

A school stores student data in a flat file. Explain two problems with this approach and how a relational database solves them.

Mark scheme
  • Redundancy: the same data (e.g. class teacher) is repeated in every record, wasting storage (1). In a relational database it is stored once in a linked table (1).
  • Inconsistency: if a repeated value is updated in one record only, the data disagrees (1). With linked tables there is only one copy to update, so the data stays consistent (1).
Exam practice 2[5]

A table Results has fields StudentID, Surname, Subject, Mark. Write an SQL query to display the Surname and Mark of all students who scored more than 70 in Physics, in descending order of Mark.

Mark scheme
  • SELECT Surname, Mark (1)
  • FROM Results (1)
  • WHERE Subject = "Physics" AND Mark > 70 (2 — one mark for each condition, quotes required for text)
  • ORDER BY Mark DESC (1)

Quick Reference

Table = records (rows) + fields (columns) Primary key = unique identifier; foreign key = link to another table Relational removes redundancy and inconsistency SQL: SELECT ... FROM ... WHERE ... ORDER BY ... GROUP BY ... Aggregates: COUNT, SUM, AVG, MAX, MIN Validation: range, length, presence, type, format, lookup