24 min read
Data Types
Text, number, date, and yes/no — each field needs a type so the computer stores values correctly.
Every field needs a data type. The type tells the computer what kind of value may go in the column — and what the computer may do with it.
Choose the wrong type and values change shape. The most famous trap: storing a phone number as a number.
The phone number trap
George Clarke sets Phone to Number because it uses digits. He types 07700 900 123. The screen shows 772345678.
The leading 0 is gone. The spaces are gone. For a Sri Lankan mobile number, that 0 matters. Nobody should add two phone numbers together.
| Same phone, two types | ||
|---|---|---|
The computer did not lose the 0 by accident. George told it Phone was a quantity. Quantities drop leading zeros. 07 and 7 are the same number — but not the same phone number.
If leading zeros, spaces, or dashes mean something, the field is text, even when it looks numeric.
Common types
The library needs several types:
- Text — names, cities, phone numbers, ID codes. Do not add them. Keep leading zeros.
- Number — counts and quantities you might calculate, such as copies on the shelf.
- Date/Time — join dates, borrowed dates. Sort them and ask "which loans are overdue?"
- Yes/No — two answers only: fine paid or not, overdue or not. Not a sentence.
| Fields and sensible types | ||
|---|---|---|
Choosing a type
| Use text when… | Use number when… |
|---|---|
| Leading zeros must stay | You might add or average values |
| The value is a code, name, or phone | The value is a count or quantity |
| Spaces and dashes are part of the value | 07 and 7 should mean the same amount |
Choose the type from the job
Practice
Swipe or use the arrows to move between questions.
1 / 3
Section check
Before you continue: tables
You know what a table is, what an entity means, how rows and columns work, and why data types matter. A quick check before keys.
This is practice, not the final assessment. Use hints. Look up a lesson if you are unsure — there is no score.
Self-check
Self-check
Select every kind of thing that should become its own table.
Self-check
Self-check
More lessons in Database Fundamentals · Next: Primary Keys · Previous: Fields and Records
