Test yourself on Databases 13 questions — drag-to-order, code completion, matching and multiple choice.
Start the quiz

Single-Table Database Design

Watch this lesson Video 9.1 · 7:12 · Fields, records, the primary key, and choosing the right data type

1. What a Database Is

A database is a structured, organised collection of data stored so that it can be searched, sorted and updated easily. Storing the same data in a plain text file or a pile of paper forms makes it slow to search and easy to corrupt.

Scope for this syllabus: you are required to work with a single-table database only. You will not be asked to design a database with two or more linked tables, and foreign keys and relationships are not examined at IGCSE. If you have seen relational database design elsewhere, set it aside for this paper — everything below concerns one table.

2. Essential Terminology

Three terms describe the structure of a single table, and they are examined directly.

TermMeaningIn a table
Field A single item of data, of one specific data type A column
Record A complete set of fields about one person, object or event A row
Primary key A field that uniquely identifies each record One designated column
A helpful way to keep these straight: a field is one fact, a record is all the facts about one thing, and the table is all the records together.

3. The Primary Key

The purpose of a primary key is to identify each record uniquely, so that no two records can be confused and any single record can be found reliably.

A suitable primary key must:

  • be different for every record — no duplicates are possible
  • never be left empty
  • not change over time

Choosing a primary key

Consider a table of students. Which field would work?

FieldSuitable?Why
FirstNameNoTwo students can share a first name
SurnameNoDuplicates are very likely
DateOfBirthNoSeveral students may share a birthday
ClassGroupNoMany students are in the same class
StudentIDYesDeliberately issued so that it is unique and never reused
Justify your choice by uniqueness. The mark is for explaining that the field is unique to each record. Answers such as "because it is a number" or "because it is the first column" score nothing. Equally, saying a name "is probably unique" is not enough — a primary key must be guaranteed unique.

4. Basic Data Types

Each field is given a data type. The syllabus limits these to six.

Data typeStoresExample
Text / alphanumericLetters, digits and symbols together14 Green Lane
CharacterA single character onlyM
BooleanOne of two values onlyTRUE / FALSE
IntegerA whole number17
RealA number with a decimal part72.5
Date/timeA calendar date and/or a time14/07/2009
A telephone number is text, not an integer. It may begin with a zero, may contain spaces or a +, and is never used in arithmetic. The same reasoning applies to postcodes and student ID codes containing letters. This is a very frequently examined point.
Choose Boolean whenever a field answers a yes/no question, such as LibraryFinePaid. Using text for this wastes space and allows inconsistent entries such as "yes", "Y" and "true" in the same column.

5. Validation in a Database

A field definition can also carry validation so that impossible data is refused as it is entered. The same checks used in programming apply here.

FieldSuitable validation
AgeRange check — between 11 and 19
StudentIDLength check — exactly 6 characters; presence check
SurnamePresence check — must not be blank
DateOfBirthFormat check — dd/mm/yyyy

6. Designing a Single Table

Given a set of storage requirements, a database definition states each field name, its data type, and which field is the primary key.

Worked example

A school library needs to store, for each book: a unique reference, the title, the author, the year of publication, the price paid, and whether it is currently on loan.

Field nameData typeNotes
BookRefText/alphanumericPrimary key — unique for every book
TitleText/alphanumeric
AuthorText/alphanumeric
YearPublishedIntegerA whole number, used in comparisons
PriceRealNeeds a decimal part
OnLoanBooleanOnly two possible values

With sample data the table looks like this:

BookRefTitleAuthor YearPublishedPriceOnLoan
LIB001Hard TimesDickens18547.99TRUE
LIB002Silas MarnerEliot18616.50FALSE
LIB003KimKipling19018.25FALSE

Each column is a field. Each row is a record. BookRef is the primary key, so no two rows can ever be mistaken for one another.

7. Exam Focus

Give a data type from the list, not a programming type. Write "text/alphanumeric", not "string" or "varchar". Write "real", not "float" or "decimal".
Do not invent extra tables. Questions on this topic supply requirements for a single table. Splitting the data across two tables with a foreign key is outside the syllabus and does not answer the question asked.
Use the exact field names given in the question. When a scenario names the data items, reuse those names in your design. Renaming them makes your answer harder to mark and can lose the mark.

Quick self-check

  • Define field, record and primary key.
  • State the purpose of a primary key in one sentence.
  • Explain why a mobile phone number should be stored as text, not integer.
  • A club stores, for each member: a membership number, name, date joined, fees paid in the year, and whether they are a committee member. Give a suitable data type for each and identify the primary key.
  • Suggest a suitable validation check for a field storing a percentage mark.