SQL constraints for validation
A constraint is a rule on a column. This CHECK rejects any record with an age outside 0 to 120. NOT NULL (must have a value) and UNIQUE (no repeats) are constraints too.
Understanding SQL constraints for validation in VCE Spreadsheets, SQL & Visualisation
What it does: UNIQUE means no value can repeat in that column, so a second record with the same email is rejected. CHECK with BETWEEN is a range check. Any mark below 0 or above 100 is rejected. CHECK is the constraint used for a range check. NOT NULL does not take a condition. The data type comes first, then the constraint: name TEXT NOT NULL. BETWEEN includes the start and end values, so 0 and 120 are both allowed. Constraints validate data on entry. They reject bad records rather than correcting them later. A CHECK constraint needs its rule inside brackets. Without them the database cannot read the rule.
Common mistakes: The condition inside a CHECK constraint must be wrapped in brackets. It should be CHECK (age >= 0). The presence check constraint is written NOT NULL, not NO NULL. It stops the column being left empty.
Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.
This module's key terms are also in a printable crossword (Modules 45–54) and word search (Modules 35–54).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
CHECK (age BETWEEN 0 AND 120)Fill in the Blanks
Spot the Error
Student with a class code? Join your class →