HelpContactFor teachers and institutes
>_StemPy Lab
Mock TestsClasses

>_StemPy Lab

Learn. Solve. Code the solutions. Test yourself.

Live examsFree mock exams, timed and rankedEveryone starts together, and your score and rank come the moment it ends.See the exams →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data Science
  • Computer Science
  • Classes
  • Groups

Practice

  • Problems
  • Quizzes
  • Mock Tests
  • Prepare for an Exam
  • Question Sets
  • Exams
  • Certificates
  • Python Labs
  • AI Practice Generator
  • Student-Created Tests

Community

  • Discussions
  • Resources
  • Notes
  • Glossary
  • Blog

Account

  • Log in
© 2026 senLearn. All rights reserved.HelpFor SchoolsAboutContactPrivacy PolicyTerms of UseRefund Policy
Database Tables, Data Types and Primary Keys
  1. 1Tables, fields and records
  2. 2Data types and the primary key
  3. 3Validation in a database table
  1. Computer Science
  2. /Database Tables, Data Types and Primary Keys
  3. /Validation in a database table

Course 9.1·Lesson 3 of 3

Validation in a database table

A database is only useful if its data is sensible. Validation is a check that the computer makes on data before it goes into a table. You choose suitable checks for each field: range, length, type, presence, format and check digit, and you write validation in Python before a record is added.

about 25 min1 simulation1 practice question
Lesson 3 of 3Show all lessonsHide
Database Tables, Data Types and Primary Keys
  1. 1Tables, fields and records
  2. 2Data types and the primary key
  3. 3Validation in a database table

Try the code and the simulations beside the lesson.

Data that makes no sense

Imagine a club list where one member is 150150150 years old and another has no surname. A search for members under 161616 would give wrong answers. Nobody typed the mistakes on purpose, but the table is now wrong.

Validation is an automatic check, made by the computer, that data is sensible before it is accepted. If the data fails the check, it is rejected and the person is asked to type it again.

Validation cannot prove that data is correct. If a member is 141414 and someone types 151515, a range check from 111111 to 181818 accepts it. The value is sensible, but wrong.

The validation checks

Each check suits a different kind of field.

  • Range check: the value is between a lowest and a highest value. An age from 111111 to 181818.
  • Length check: the number of characters is right, or within limits. A member ID has exactly 333 characters, a password has at least 888.
  • Type check: the value is of the right data type. An age must be a whole number, not "twelve".
  • Presence check: something has been entered. A surname must not be left empty.
  • Format check: the characters follow a pattern. A member ID is the letter M and then two digits, such as M07.
  • Check digit: the last digit of a code is worked out from the other digits. A typing mistake makes the digits disagree. Chapter 2 shows how the digit is found.
A flow diagram. A box 'data typed in' leads to a diamond 'passes every validation check?'. The arrow marked Yes goes to a box 'record stored in the table'. The arrow marked No goes to a box 'rejected: error message, type it again', and an arrow from there goes back to 'data typed in'. Beside the diamond is a list of the checks: range, length, type, presence, format, check digit.

Choosing checks for a table

When you define a table, you say which checks each field needs. Here is a plan for the Members table.

  • MemberID: presence check, length check (exactly 333 characters) and format check (M and two digits).
  • Surname: presence check.
  • Age: type check (an integer) and range check (111111 to 181818).
  • Paid: the field is Boolean, so only TRUE or FALSE can be stored.

A field can have more than one check. Ask: what would a wrong value look like, and which check would catch it?

Validation and verification. Validation checks that data is sensible. Verification checks that data was copied correctly: a visual check (reading it again) or a double entry check (typing it twice and comparing). Chapter 7 teaches both in algorithms.

Testing a check

Test a range check at its ends. For an age from 111111 to 181818, try 111111 and 181818 (both accepted), then 101010 and 191919 (both rejected). A check written with < where it needed <= fails on the end values.

Practise with new numbers

Try it in Python

The program checks each new member before it goes into the table. It makes a presence check, a format check and a range check. Only the records that pass all the checks are added with executemany.

Read it first. Then run it. Which records are rejected, and by which check?

1. Change the age of M09 from 19 to 18. Predict how many records are added now.

2. Add a record with the ID m10. Which check rejects it?

Common mistakes

  • Thinking validation proves the data is right. It only shows the data is sensible.
  • A range check for a code. A code needs a length check or a format check. A range check is for numbers and dates.
  • Forgetting the end values. A range from 111111 to 181818 accepts both 111111 and 181818.
  • Mixing up validation and verification. Validation: is it sensible? Verification: was it copied correctly?

Remember these

  • Validation is an automatic check that data is sensible before it is stored.
  • The checks: range, length, type, presence, format and check digit.
  • One field can need several checks.
  • Validation cannot tell whether a sensible value is the true one.

Check yourself

Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.

  1. Which check makes sure that a field Email has not been left empty?
  1. A field Floor in a hotel table must be a whole number from 000 to 121212. Name two checks it needs.
  1. A product code is two letters and then four digits, such as TB4410. Which check makes sure the code follows that pattern?
  1. An age is typed as 141414 but the member is really 131313. Will a range check from 111111 to 181818 catch it?
  1. A range check accepts whole numbers from 555 to 999. Which test values check both ends and both sides of the range?

References

  • Cambridge International, IGCSE Computer Science 0478 syllabus (exams in 2026, 2027 and 2028), section 9 Databases, 9.1 (validation), with the validation checks listed in section 7.5.

Enroll free in Database Tables, Data Types and Primary Keys

Every lesson is open to read. Enrolling also lets you:

  • Mark lessons done and carry on where you stopped.
  • Take the tests of this lesson and its course.
  • Count the course towards the certificate for its chapter.
No payment. You can leave at any time.

Problems (3)

A hotel stores its bookings in a table. For each field, choose one suitable validation check and…Easy · High School (9–10) · by StemPy Lab
A table of part-time jobs has a field HoursPerWeek…Medium · High School (9–10) · by StemPy Lab
A hotel validates each booking before it is added…Hard · High School (9–10) · by StemPy Lab
That was the last lessonBack to the course: take the test
← Database Tables, Data Types and Primary Keys
← Data types and the primary keyNext →

Discussion (0)

Log in to join the discussion.

Loading…

1 Python program
5 questions to check yourself

This lesson is free to read. Enroll free to keep your place and take the tests.

Python Labs (1)

Validation checks before a record is storedPython Lab · by StemPy Lab

Question Sets (1)

Database Tables: Check Your Understanding10 questions · by StemPy Lab

Notes (1)

Database Tables and Keys: Quick RevisionNote · by StemPy Lab