GoalChoose a clear name and the right data type (text, number or date) for each field.
New words
data type · the kind of data that a field holds, such as text, number or datetext · letters, symbols and digits that are used as labels, not for calculatingnumber · a value that we can count, add, subtract or comparedata validation · a rule in a spreadsheet that checks whether the data typed in has the right type
Explanation
Every field has a name and a data type. The name should be short and say what the data is. The data type says what kind of data the field holds. Text is for words and for codes, even if the code has digits in it. Number is for values that we count or calculate with. Date is for days, months and years. A field with the right type is easier to sort and check. We ask one question: will we add, subtract or compare this as a quantity? If yes, use number. A telephone number or a code such as R-104 is only a label, so it is text. In a spreadsheet, data validation can make a column accept only one type.
Data item
Field name
Data type
Why
repair job code, such as R-104
Job code
text
a label with a letter, never calculated
kind of bike, such as mountain
Bike type
text
a word
day the bike came in
Date booked
date
a calendar day
number of days to repair
Days needed
number
we can add and compare it
Worked examples
Phone numbers are stored as text, although they are made of digits. We never add two phone numbers together. Also, a number field would drop a zero at the front, so 0412 would become 412. A text field keeps exactly what was typed.
Sorted as text
Sorted as dates
10 Jan
2 Jan
2 Jan
9 Jan
9 Jan
10 Jan
Dates need their own type. Sorted as text, the dates ‘10 Jan’, ‘2 Jan’ and ‘9 Jan’ come out in this order because 1 comes before 2 and 9. Sorted as dates they come out in the right order. The same happens with numbers stored as text.
Units belong in the field name, not in the data. A field called ‘Weight (kg)’ holds 3, not ‘3 kg’. Then the field can be a number, and we can add the weights or find the biggest.
Class activity
Bags of types (no computer): write twelve data items on slips of paper, such as 12 July, B-12, tulip, 85, red, 7 March, 0042, 3.5. Make three bags called text, number and date. Sort the slips. Which ones were tricky? Talk about why B-12 and 0042 are text. Then think of two new slips for each bag. If you have a computer or tablet, type the items into three columns of a spreadsheet and find out what it does when you type text into a number column that uses data validation.
Practice
1
Choose the data type for each field in a database of fish in a pond. What is the data type of: Fish code (FS-31), Length in cm (7), Date bought (4 June), Kind of fish (guppy), Number of fish (12)?
Field name
Example
Data type
Fish code
FS-31
?
Length in cm
7
?
Date bought
4 June
?
Kind of fish
guppy
?
Number of fish
12
?
Fish code: text. Length in cm: number. Date bought: date. Kind of fish: text. Number of fish: number.
2
Explain why a telephone number should be stored as text.
We never calculate with phone numbers, and a number field would drop a zero at the front. A text field keeps it exactly as it was typed.
3
Put 100, 12 and 9 in order from the smallest, first as numbers, and then as text.
As numbers: 9, 12, 100. As text, the characters are compared one at a time: 100, 12, 9.
4
Which of these are good field names, and which are poor? ‘Data1’, ‘Class name’, ‘The name of the class that the pupil belongs to in school’, ‘Date of birth’.
Field name
Data1
Class name
The name of the class that the pupil belongs to in school
Date of birth
‘Class name’ and ‘Date of birth’ are good: they are short and clear. ‘Data1’ says nothing about the data. The long name is too long.