Database Fundamentals · Cambridge syllabus 9.1, 9.2 · Lesson 2 of 2
Data Types
Field types define the kind of values allowed and how they can be processed. The syllabus names text/alphanumeric, character (one character), Boolean, integer, real and date/time. Text preserves identifiers and leading zeros; integer and real support arithmetic; Boolean fields represent two states. Select types from meaning rather than visual appearance.
By the end, you can
- Select suitable basic data types.
- Use the text/alphanumeric, character, Boolean, integer, real and date/time data types.
- Explain why selecting suitable data types matters.
Database field types
Each field is given a data type, which decides what can be stored in it, how much space it takes, how it sorts, and what can be done with it.
The syllabus names six types. Text, also called alphanumeric, holds letters, digits and symbols: names, addresses, descriptions, and any code that is not used in arithmetic. Character holds exactly one character, such as a grade A to E or a size code S, M or L. Integer holds whole numbers — a quantity in stock, a number of pages — and real holds numbers with a fractional part, such as a price or a weight.
Date/time stores a real date or time rather than text that looks like one, which is what allows sorting into chronological order and calculating the difference between two dates. Boolean holds one of two values and suits anything with exactly two states: on loan or not, paid or not, member or not.
The choice has consequences that show up later. A date stored as text sorts alphabetically, so 02/01/2025 comes before 15/12/2024, and no arithmetic is possible on it. A number stored as text sorts as 1, 10, 2, 20, 3. A Boolean stored as the words Yes and No allows a typo of Y, yes or YES, and now three values mean the same thing.
Going the other way is just as wrong: a telephone number, a postcode or a product code stored as a number loses any leading zero and invites arithmetic that means nothing. The test is whether the value is ever calculated with. If not, it is text however numeric it looks.
Worth remembering
- Text/alphanumeric, character, Boolean, integer, real and date/time.
- A date stored as text sorts alphabetically and cannot be calculated with.
- A telephone number is text: it may start with zero and is never arithmetic.
Worked example
A product code "0012" should normally be text if leading zeros are significant and arithmetic is unnecessary.
Practice
Warm-up · not marked
Check your understanding
Answer in your own words, then compare with the worked answer. Nothing here is saved or scored.
Worked answer
Boolean, because the field has two states such as true and false.
Check your method, units and explanation against it.
Marked practice
Set 1 of 5 · easiest first · Checked as you go, with the worked answer. Sign in or create a free account to save your progress.