Changing data across related tables
Add the parent row before its child rows, and delete child rows before their parent. Otherwise the foreign key rule is broken and SQL gives a foreign key error.
Understanding Changing data across related tables in QCE Digital Solutions Unit 2
What it does: The subject (parent) is added first, then the result (child) uses subjectId 6 as its foreign key. Foreign key errors on insert usually mean the value in the foreign key column has no matching primary key in the parent table. The student must exist in students before an order can use studentId 11 as its foreign key.
Common mistakes: Line 1 deletes the parent row first while child rows in orders still point to it, so SQL gives a foreign key error. Line 1 should be DELETE FROM orders so the child rows go first. The child row uses subjectId 9, but no parent row with that ID exists in subjects, so the foreign key rule is broken. It should use an existing subject ID such as 3.
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 337–409) and word search (Modules 234–409).
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
INSERT parent, DELETE childFill in the Blanks
Spot the Error
Student with a class code? Join your class →