Data Validation (SQA National 5 Computing Science): Revision Note

Exam code: X816 75

Robert Hampton

Written by: Robert Hampton

Reviewed by: James Woodhouse

Updated on

Data validation

What is data validation?

  • Data validation is an automated process used to check that input data is sensible and meets the rules of the program or database

  • It helps reduce errors by preventing invalid data from being entered or stored

  • Validation does not check that data is accurate, only that it follows defined rules

Types of validation

  • There are several types of validation that can be applied to fields in a database:

Validation type

Purpose

Example

Range check

Ensures data falls within a given range

A percentage must be between 0 and 100 inclusive

Length check

Ensures data has a set number of characters

A PIN must be exactly 4 digits long

Type check

Ensures data is of the correct data type

Age must be a number, not text

Presence check

Ensures required fields are not left blank

A username must be entered

Restricted choice

Ensures only valid options can be selected

Gender field can only contain Male or Female

Format check

Ensures data follows a specific pattern

A postcode follows the format “EH12 3AB”

Worked Example

Scenario: The Online Pet Store

An online pet store is developing a program to calculate loyalty points and is simultaneously updating its product database.

The pet store's central product database is being designed. The following table (Entity: Product) stores details about the available pet products.

Attribute name

Type

Required

Validation

productID (PK)

Number

Y

productName

Text

Y

(i)

category

Text

Y

(ii)

stockLevel

Number

Y

(iii)

SKU

Text

Y

Length = 8

Based on the following rules, complete the validation column for the attributes marked (i), (ii), and (iii):

  • The productName must always have a value entered

  • The category can only be one of 'Dog', 'Cat', or 'Fish'

  • The stockLevel must be greater than or equal to 0, and less than or equal to 999

Attribute name

Validation

Type of Check

(i) productName

(ii) category

(iii) stockLevel

[3]

Answer

Attribute name

Validation

Type of Check

(i) productName

Presence Check

Presence [1 mark]

(ii) category

Restricted Choice: Dog, Cat, Fish

Restricted Choice / Lookup [1 mark]

(iii) stockLevel

Range: >= 0 AND <= 999

Range [1 mark]

Unlock more, it's free!

Join the 100,000+ Students that ❤️ Save My Exams

the (exam) results speak for themselves:

Robert Hampton

Author: Robert Hampton

Expertise: Computer Science Content Creator

Rob has over 16 years' experience teaching Computer Science and ICT at KS3 & GCSE levels. Rob has demonstrated strong leadership as Head of Department since 2012 and previously supported teacher development as a Specialist Leader of Education, empowering departments to excel in Computer Science. Beyond his tech expertise, Robert embraces the virtual world as an avid gamer, conquering digital battlefields when he's not coding.

James Woodhouse

Reviewer: James Woodhouse

Expertise: Computer Science & English Subject Lead

James graduated from the University of Sunderland with a degree in ICT and Computing education. He has over 14 years of experience both teaching and leading in Computer Science, specialising in teaching GCSE and A-level. James has held various leadership roles, including Head of Computer Science and coordinator positions for Key Stage 3 and Key Stage 4. James has a keen interest in networking security and technologies aimed at preventing security breaches.