Database Design & Development · Design

DDD5 — Validation: presence check, restricted choice, field length, range

📅 To be scheduled
~50–60 minutes · single period
Learning intentions
Success criteria
Warm up — what do you already know?

Answer before the lesson begins — it's fine if you're unsure.

WU1
1. In DDD4 you gave qualified (Instructor) a data type. What data type is it?
WU2
2. What is the field size given to postcode (Member) in DDD4's data dictionary?
WU3
3. National 5 recap: what do we call a check that stops a record being saved if a required field has been left blank?

Key vocabulary

Validation
An automatic check applied when data is entered, to catch data that is clearly wrong before it's stored.
Presence check
Confirms a required field has not been left blank.
Restricted choice
Confirms a value matches one from a fixed, pre-defined list of allowed values.
Field length check
Confirms the number of characters entered does not exceed a stated maximum.
Range check
Confirms a numeric value falls within a stated minimum and maximum.

Validating the data dictionary

What is validation, and why does it matter?

Validation is an automatic check applied when data is entered into a database, designed to catch data that is clearly wrong before it gets stored. Validation cannot guarantee data is correct — a presence check on firstName would happily accept "Xyzzy" as a first name — but it can catch data that is clearly invalid, like a blank required field or a day of the week that doesn't exist. The Higher course names exactly four validation types, and no others: presence check, restricted choice, field length, and range.

Presence check

A presence check confirms that a required field has not been left blank. It's the simplest validation type, and it's applied to any attribute the database genuinely cannot function without — most obviously, primary keys. Member's memberID needs a presence check, because a booking system cannot process a member record with no ID.

Restricted choice

A restricted choice check confirms that an entered value matches one item from a fixed, pre-defined list of allowed values — anything not on the list is rejected. Class's dayOfWeek is a natural fit: the only valid values are Monday through Sunday, so a restricted choice check against that exact list of seven values catches typos like "Mundy" immediately. Boolean attributes like qualified and attended are also, in effect, restricted choice checks with only two allowed values: True and False.

Field length check

A field length check confirms that the number of characters entered does not exceed the field size set in the data dictionary. If postcode has a field size of 8, a field length check rejects any entry longer than 8 characters — protecting against data that would otherwise be silently truncated or cause a storage error.

Range check

A range check confirms that a numeric value falls between a stated minimum and maximum. Class's capacity is a strong example: a class can't sensibly have a capacity of 0 or a capacity of 500 in a small sports hall, so a range check of, say, 1 to 30 catches obviously wrong entries — a capacity of -5 or 999 — that would otherwise be accepted as valid numbers.

Extending the data dictionary

Adding validation to a data dictionary means adding one more column — Validation — to the structure already built in DDD4 (entity, attribute, PK/FK, data type, field size). Every attribute's validation entry should be specific and exemplified, not just the type name: "Range check, 1–30" is a complete answer; "range check" alone is not, because it doesn't state which range.

Start: pick an attribute from the data dictionary Must this field always contain a value? Presence check if no → Is there a fixed, short list of valid values? Restricted choice if no → Is it text with a stated maximum length? Field length check if no → Is it numeric with a sensible min and max? Range check
A repeatable method: work down the questions in order, and the first "yes" gives the appropriate validation type. Some attributes (like memberID) genuinely answer "yes" to more than one question.

Worked examples

Example 1 — Presence check on memberID
1
Attribute: memberID (Member's primary key).
2
Ask: can the database function correctly if this field is left blank? No — every Member record needs an ID to be uniquely identifiable and linked to from Booking.
Validation: Presence checkmemberID must not be left blank.
Example 2 — Restricted choice on dayOfWeek
1
Attribute: dayOfWeek (Class).
2
Ask: is there a fixed, known list of every value this attribute could ever validly hold? Yes — there are only seven possible days.
Validation: Restricted choicedayOfWeek must be one of: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday.
Example 3 — Field length and range on postcode and capacity
1
Attribute: postcode (Member), field size 8. Ask: is there a fixed maximum length? Yes — the field size itself sets it.
2
Validation: Field length checkpostcode must not exceed 8 characters.
3
Attribute: capacity (Class). Ask: is there a sensible numeric minimum and maximum? Yes — a realistic class size.
Validation: Range checkcapacity must be between 1 and 30.
EntityAttributePK/FKData typeField sizeValidation
MembermemberIDPKText6Presence check
MemberpostcodeText8Field length check, max 8 characters
ClassdayOfWeekText10Restricted choice: Monday–Sunday
ClasscapacityNumbern/aRange check, 1–30
ClassfeePerSessionNumbern/aRange check, 0–50
InstructorqualifiedBooleann/aRestricted choice: True, False
Now you try

Booking's bookingRef is a text primary key (field size 8), and attended is a Boolean. State an appropriate, specific validation rule for each.

  • bookingRefPresence check (it's the primary key, so it must not be left blank) — you could also add a field length check of max 8 characters, since both are genuinely applicable here.
  • attendedRestricted choice: must be True or False.
⚠️ Common mistakes — examiner feedback
📝 Exam tip

When asked to "exemplify" validation, always state the actual rule — the specific list, the specific maximum length, or the specific numeric range — rather than only naming which of the four types applies. A correct type name with no specific value attached typically only earns partial credit.

Task Set B — Core questions
Work through all questions. Written answers use self-assessment — compare with the model answer.
B1
Name the four validation types required at Higher (comma-separated).
B2
Which validation type would best suit Class's className (e.g. "Pilates", "Yoga")?
B3
State a specific, exemplified validation rule for Class's capacity (using the range 1–30 established in the worked examples).
B4
Why is restricted choice a better fit for dayOfWeek than for surname?
B5
Which validation type checks that the number of characters entered doesn't exceed a stated maximum?
B6
Add a validation column for every attribute in the Member entity (memberID, firstName, surname, address, town, postcode, dateJoined), using DDD4's data dictionary as your starting point.
Model answer
B7
Why is a format check (e.g. checking for an @ symbol in an email address) not part of this lesson's four validation types?
B8
State a specific, exemplified validation rule for Instructor's qualified.
B9
Explain why validation cannot guarantee that data entered into the database is correct, even when every field passes its validation check.
Model answer
Task Set C — Extension · Beyond the specification
Optional challenge questions. Not required for your exam.
C1
Could a range check meaningfully be applied to a date attribute like bookingDate, not just a number like capacity? Explain how this would work differently.
One possible answer
C2
Could a single attribute need more than one validation rule at once? Give a specific example from the sports club scenario and justify it.
One possible answer
C3
What happens to a restricted choice validation rule if the real-world list of valid values changes later (for example, the club adds Sunday classes for the first time)? What does this suggest about a genuine limitation of restricted choice compared to the other three validation types?
One possible answer

📁 File this in OneNote under:
Higher Computing Science → Database Design & Development → DDD5

📌 Teacher notes — Shift+T to hide

Suggested timing: 8 min warm up · 15 min notes (four validation types) · 15 min worked examples · 5 min now you try · 20 min Task Set B · 5–10 min Task Set C / review, if time allows.

Key misconception: pupils often name a validation type without stating the specific rule (e.g. writing "range check" instead of "range check, 1–30"). Model the exemplified form every time in class, and dock marks consistently for un-exemplified answers in feedback, matching how SQA's own marking instructions expect specifics.

Spec-accuracy note: do not introduce format check or check digit as a fifth/sixth validation type, even informally — these are National 5 techniques and are confirmed absent from the Higher DDD content statement (see ddd/DDD.md §1).

SQA command words covered: "exemplify" (state the actual rule, not just the type name — see the exam tip box), "describe".

Extension suggestion: pupils who finish Task Set C early could complete a full validation column for every attribute across all four entities, cross-checking against DDD4's complete data dictionary.