Choosing a data type for a value

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Choosing a data type for a value

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. A school database stores a student's postcode, such as 0800 for a remote area. Which data type is best?
A Text, because you never do maths on a postcode
B Integer, because a postcode is made of digits
2. You want to add up the price of every item in a canteen order, such as $4.50 and $3.95. Which data type suits the price field?
A Floating point, because prices have cents
B Integer, because prices are numbers
3. You need to sort a list of events from earliest to latest. Which data type should store the event day?
A Text
B Date/time
4. A field records whether a student has returned their permission form (yes or no). Which data type is the best choice?
A Boolean, because the value is only true or false
B Text, because you type the word Yes or No
5. Which statement about choosing a data type is correct?
A Choose the type based on what the value looks like
B Choose the type based on what you will do with the value

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1postcode: Text APostcode was given a number type, so the leading zero is dropped and the postcode is now wrong
2price: Floating point BStore a postcode as text because you never do maths on it and it can start with 0 (like 0800)
3Choose the data type by what you will do with the value, such as sorting events in order of when they happen Chas_paid: Boolean
4A value that you only test as true or false should use the Boolean type DStore a price as a number with decimals so you can add, multiply and work out totals
5postcode: Integer (0800 is stored as 800) EPrice was given a text type, so values are joined together instead of added, giving a wrong result
6price: Text (total of $5 + $10 gives "510") Fevent_date: Date/time

Definitions

data type

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
Postcode: ____
2.
Price (e.g. 12.50): ______________
3.
DateJoined: _________
4.
IsMember: _______
5.
Quantity: _______ Total ← Quantity * 5

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A Table: Customer
B Postcode : Integer
C Price : Float
D Joined : Date/time
Question 2
A Table: Product
B Name : Text
C Price : Float
D InStock : Text
Question 3
A Table: Order
B OrderID : Integer
C OrderDate : Text
D Total : Float
Question 4
A price ← 4.50
B qty ← "3"
C total ← price * qty
D OUTPUT total
Question 5
A Table: Member
B Name : Text
C Postcode : Text
D Age : Text

Answer Key

Choosing a data type for a value
Section A: Quick Questions
Q1
A — Text, because you never do maths on a postcode
Q2
A — Floating point, because prices have cents
Q3
B — Date/time
Q4
A — Boolean, because the value is only true or false
Q5
B — Choose the type based on what you will do with the value
Section B: Match the Pairs
Q1
postcode: Text → Store a postcode as text because you never do maths on it and it can start with 0 (like 0800)
Q2
price: Floating point → Store a price as a number with decimals so you can add, multiply and work out totals
Q3
Choose the data type by what you will do with the value, such as sorting events in order of when they happen → event_date: Date/time
Q4
A value that you only test as true or false should use the Boolean type → has_paid: Boolean
Q5
postcode: Integer (0800 is stored as 800) → Postcode was given a number type, so the leading zero is dropped and the postcode is now wrong
Q6
price: Text (total of $5 + $10 gives "510") → Price was given a text type, so values are joined together instead of added, giving a wrong result
Section C: Definitions
Q1
data type — Pick the data type by what you will do with the value: calculate (number), sort by date (date/time), test true or false (Boolean). Postcodes are text, not numbers, as you never do maths on them.
Section D: Fill in the Blanks
Q1
Postcode: Text
Q2
Price (e.g. 12.50): Floating point
Q3
DateJoined: Date/time
Q4
IsMember: Boolean
Q5
Quantity: Integer Total ← Quantity * 5
Section E: Spot the Error
Q1
B — Postcodes are never used in calculations, so they should be Text. An Integer drops leading zeros (0800 becomes 800). The line should be Postcode : Text.
Q2
D — InStock is tested as true or false, so it should be Boolean. Text would let any word be stored and makes true/false tests unreliable. It should be InStock : Boolean.
Q3
C — You sort orders by date, so OrderDate needs the Date/time type. As Text, 10/02 would sort before 2/03. It should be OrderDate : Date/time.
Q4
B — The quotes make qty Text, so you can't multiply it by price. A quantity you calculate with should be a whole number: qty ← 3.
Q5
D — Age is used in calculations such as averages and comparisons, so it should be a number. As Text it can't be added or averaged. It should be Age : Integer.