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
  1. Problems
  2. /A hotel validates each booking before it is added…
HardComputer ScienceHigh School (9–10)Computer Science › Databases and SQLNumericalIGCSE

A hotel validates each booking before it is added…

StemPy LabContributed by StemPy Lab

Try it on paper first. A hint, the key idea and the worked solution are here when you need them.

A hotel validates each booking before it is added. The checks are made in this order, and a booking stops at the first check it fails.

  1. Format check: BookingRef is H followed by four digits.
  2. Presence check: GuestName is not empty.
  3. Range check: Nights is from 111 to 777.

These bookings are typed in (reference, name, nights): (H2041, Diaz, 2), (H2042, empty, 3), (H204, Kato, 1), (H2044, Moyo, 9), (H2045, Berg, 4), (X2046, Hale, 2), (H2047, Nkosi, 0), (H2048, Ivanova, 6).

How many bookings are added? How many are rejected by each check?

Check your answer

Work it out on paper, then type your number. The answer itself stays hidden.

Need a reminder? The key ideaShowHide

Validation is an automatic check that data is sensible before it is stored: a range check, a length check, a type check, a presence check, a format check or a check digit. A field can need several checks. Validation cannot prove that a sensible value is the true one.

The worked solution

Have you tried it?

Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.

Plan. Take each booking in turn and apply the checks in order. A booking that fails is counted once, at the first check it fails.

Step 1. The format check. H204 has only three digits, and X2046 starts with X. So 222 bookings fail here.

Step 2. The presence check. Of the rest, only H2042 has no name: 111 booking.

Step 3. The range check. Of the rest, H2044 has 999 nights and H2047 has 000 nights. Both are outside 111 to 777: 222 bookings.

Step 4. The bookings added. H2041, H2045 and H2048 pass all three checks: 333 bookings.

Check. 3+2+1+2=83 + 2 + 1 + 2 = 83+2+1+2=8, the number of bookings typed in.

Watch out. 000 nights is outside the range, even though 000 looks harmless. A range check has a lowest value too.

Answer: 333 bookings are added. The format check rejects 222, the presence check 111 and the range check 222.

Log in to save this for later
← All Problems
← A table of part-time jobs has a field HoursPerWeek…A stationery cupboard keeps its pens in a table Pens… →
More onComputer Science › Databases and SQL

Discussion (0)

Log in to join the discussion.

Loading…

Learn it in

  1. Validation in a database tableDatabase Tables, Data Types and Primary Keys

More on this topic

  1. A restaurant stores its staff in a table Staff…Hard
  2. A town library stores its readers in a table Readers…Medium
  3. A gym stores its members in a table Gym…Easy
  4. A school garden club records each plot in a table Plots: the water it needs each day in litres, its…
Hard
  • A school weather station stores one record a day in a table Weather: the rainfall in millimetres…Medium
  • All problems on this topic →