Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Preview

AESP task 2: Find missing, wrong and impossible values

This is the first page of the lesson. Read it and have a go at the activities. The rest is in the full lesson.

60 minutes

A deposit of minus thirty pounds

Row 7 says a member paid in -30 pounds. Row 9 says 5000. Row 6 says "twenty". Row 5 says nothing at all.

Each one breaks a different rule. Each one needs a different test.

Key words

WordWhat it means
Nulla value that is missing: there is nothing in the cell
Data typethe kind of value a column holds, such as a number, text or a date
Rangethe lowest and highest values that make sense
Boundary datatest values at the very edge of a range
Erroneous datadata that is wrong and should be refused
Validationa check that data is sensible when it comes in
SQLa language for asking questions of data kept in tables
Querya question you ask of data, written in SQL
Test datathe values you feed into a test
Normal dataordinary values that should be accepted

The cells students fill in are left blank in this preview.

By the end of this lesson

Note

I can write tests that find missing values, wrong types, out of range values and bad dates, and choose test data at the boundaries.

Starter

Have a go

Starter

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Your answers are marked here and are not kept. A college account keeps every student’s marks.

This is practice

Important

The real task comes from the exam board. This lesson uses an invented organisation and its own made-up data. Your teacher tells you how the real tasks are set and what you may bring.

Worked example: four rules for the amount

RulePlain wordsSQL idea
PresentEvery deposit has an amountamount IS NULL finds the gaps
TypeThe amount is a numbertypeof(amount) shows what is stored
RangeFrom 1 to 1000 poundsamount < 1 OR amount > 1000
DateThe date is a real datedate(deposit_date) gives null if it is not

The cells students fill in are left blank in this preview.

Run it: missing and wrong type

Code: sql
SELECT deposit_id, typeof(amount) AS stored_as, amount
FROM deposit
WHERE amount IS NULL OR typeof(amount) <> 'real';

Never write = NULL

Warning

A missing value is not equal to anything, not even to another missing value. So amount = NULL finds nothing. Write amount IS NULL.

Run it: range and date

Code: sql
SELECT deposit_id, deposit_date, amount
FROM deposit
WHERE typeof(amount) = 'real' AND (amount < 1 OR amount > 1000)
   OR date(deposit_date) IS NULL;

The lesson goes on

8 more parts of this lesson are in the full curriculum, with the tasks, the final check and the labs. A college account gives your students all of it.