AdvertisementYour brand could be hereYour brand hereOn every Darslab page · students, parents and teachersinfo@darslab.comAsk for pricesPricesinfo@darslab.com
☰ Year plan · Computing

Design a table

Week 16 · Unit 7: Be a data architect · 3 lessons
2

Fields and data types

Computing 6: Unit 7, pp. 92–105
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 itemField nameData typeWhy
repair job code, such as R-104Job codetexta label with a letter, never calculated
kind of bike, such as mountainBike typetexta word
day the bike came inDate bookeddatea calendar day
number of days to repairDays needednumberwe 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 textSorted as dates
10 Jan2 Jan
2 Jan9 Jan
9 Jan10 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 nameExampleData type
Fish codeFS-31?
Length in cm7?
Date bought4 June?
Kind of fishguppy?
Number of fish12?
2
Explain why a telephone number should be stored as text.
3
Put 100, 12 and 9 in order from the smallest, first as numbers, and then as text.
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