Field sizes

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

Field sizes

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. A field is set as VARCHAR(30). What does the 30 mean?
A The value can be up to 30 characters long
B The value must be the number 30
2. A State field holds values like 'VIC' and 'NSW'. Which size fits best?
A VARCHAR(3)
B VARCHAR(255)
3. A field is VARCHAR(10). A user enters 'Christopher' (11 characters). What can happen?
A The field grows automatically to fit it
B The value is rejected or cut off to fit
4. Which statement about field sizes is true?
A Every field should use the largest possible size
B Smaller field sizes save storage space
5. Which field definition sets a maximum text length of 50 characters?
A LastName VARCHAR(50)
B LastName VARCHAR[50 characters]

Match the Pairs

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

Left columnRight column
1firstName VARCHAR(30) AThe postcode field is set to a size of exactly 4 characters
2postcode CHAR(4) ByearLevel TINYINT
3A field size sets the maximum length of text a value may use, so a short code only needs a small size CA size of 10 is too small for most email addresses, so many values would be rejected or cut off.
4A smaller field size saves storage, so a field holding a small whole number can use a small number type DstateCode VARCHAR(3)
5INSERT INTO students (house) VALUES ('Burgundy Dragons'); -- house VARCHAR(5) EThe firstName field can store text up to a maximum of 30 characters
6email VARCHAR(10) FThe value has 16 characters but the field size only allows 5, so it will be rejected or cut off.

Definitions

VARCHAR(30)

Fill in the Blanks

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

1.
-- Text of varying length, max 30 firstName _______(30)
2.
-- Names may be up to 30 characters firstName VARCHAR(__)
3.
-- State code, always 3 characters state CHAR(_)
4.
-- Australian postcodes have 4 digits postcode CHAR(_)
5.
-- 6 digits in total, 2 after the point price DECIMAL(_,2)

Spot the Error

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

Question 1
A CREATE TABLE students (
B studentId INT,
C firstName VARCHAR[30],
D house VARCHAR(10)
E );
Question 2
A CREATE TABLE products
B name VARCHAR(50),
C price DECIMAL(6,2)
D );
Question 3
A postcode CHAR(four),
B suburb VARCHAR(40),
C state CHAR(3)
Question 4
A -- Houses: Red, Blue, Green
B -- Longest name: 5 characters
C house VARCHAR(3)
Question 5
A -- Smaller sizes save storage
B -- Choose smallest size needed
C -- Y/N flag needs 1 character
D member CHAR(255)

Answer Key

Field sizes
Section A: Quick Questions
Q1
A — The value can be up to 30 characters long
Q2
A — VARCHAR(3)
Q3
B — The value is rejected or cut off to fit
Q4
B — Smaller field sizes save storage space
Q5
A — LastName VARCHAR(50)
Section B: Match the Pairs
Q1
firstName VARCHAR(30) → The firstName field can store text up to a maximum of 30 characters
Q2
postcode CHAR(4) → The postcode field is set to a size of exactly 4 characters
Q3
A field size sets the maximum length of text a value may use, so a short code only needs a small size → stateCode VARCHAR(3)
Q4
A smaller field size saves storage, so a field holding a small whole number can use a small number type → yearLevel TINYINT
Q5
INSERT INTO students (house) VALUES ('Burgundy Dragons'); -- house VARCHAR(5) → The value has 16 characters but the field size only allows 5, so it will be rejected or cut off.
Q6
email VARCHAR(10) → A size of 10 is too small for most email addresses, so many values would be rejected or cut off.
Section C: Definitions
Q1
VARCHAR(30) — Field size sets the maximum length or storage a value may use. VARCHAR(30) allows up to 30 characters; longer values are rejected or cut. Smaller sizes save storage.
Section D: Fill in the Blanks
Q1
-- Text of varying length, max 30 firstName VARCHAR(30)
Q2
-- Names may be up to 30 characters firstName VARCHAR(30)
Q3
-- State code, always 3 characters state CHAR(3)
Q4
-- Australian postcodes have 4 digits postcode CHAR(4)
Q5
-- 6 digits in total, 2 after the point price DECIMAL(6,2)
Section E: Spot the Error
Q1
C — The field size must go in round brackets, not square brackets. It should be VARCHAR(30).
Q2
A — The opening bracket is missing. The field definitions, including their sizes such as VARCHAR(50), must start after CREATE TABLE products (
Q3
A — A field size must be a number inside the brackets. It should be CHAR(4).
Q4
C — 'Green' has 5 characters, so a size of 3 would reject it or cut it to 'Gre'. The size should be VARCHAR(5).
Q5
D — A Y/N flag needs only 1 character. A size of 255 wastes storage. It should be CHAR(1).