Data Validation (SQA National 5 Computing Science): Revision Note
Exam code: X816 75
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 |
|---|---|---|---|
| Number | Y | |
| Text | Y | (i) |
| Text | Y | (ii) |
| Number | Y | (iii) |
| Text | Y | Length = 8 |
Based on the following rules, complete the validation column for the attributes marked (i), (ii), and (iii):
The
productNamemust always have a value enteredThe
categorycan only be one of 'Dog', 'Cat', or 'Fish'The
stockLevelmust be greater than or equal to 0, and less than or equal to 999
Attribute name | Validation | Type of Check |
|---|---|---|
(i) | ||
(ii) | ||
(iii) |
[3]
Answer
Attribute name | Validation | Type of Check |
|---|---|---|
(i) | Presence Check | Presence [1 mark] |
(ii) | Restricted Choice: Dog, Cat, Fish | Restricted Choice / Lookup [1 mark] |
(iii) | Range: >= 0 AND <= 999 | Range [1 mark] |
Unlock more, it's free!
Did this page help you?