Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1INSERT INTO students VALUES (11, 'Tom', 'Ng', 7, 'Red', 0); INSERT INTO orders VALUES (11, 11, 2, 1, '2026-03-01'); | AINSERT INTO subjects VALUES (6, 'Art', 'Ms Cho'); INSERT INTO results VALUES (1, 6, 90); | |
| 2DELETE FROM orders WHERE studentId = 3; DELETE FROM students WHERE studentId = 3; | BDELETE FROM results WHERE subjectId = 5; DELETE FROM subjects WHERE subjectId = 5; | |
| 3Insert the parent record before the child record, so the foreign key value already exists in the parent table. | CThe child row is inserted before its parent. Order 11 refers to studentId 11, which does not exist yet, so SQL gives a foreign key error. Insert the student first. | |
| 4Delete child records before the parent record, so no child row is left pointing at a missing parent. | DThe parent row is deleted before its child rows. The orders still point to student 3, so SQL gives a foreign key error. Delete the orders first. | |
| 5INSERT INTO orders VALUES (11, 11, 2, 1, '2026-03-01'); INSERT INTO students VALUES (11, 'Tom', 'Ng', 7, 'Red', 0); | ERemoves the child rows (orders for student 3) first, then deletes the parent student row without breaking the foreign key. | |
| 6DELETE FROM students WHERE studentId = 3; DELETE FROM orders WHERE studentId = 3; | FAdds the parent row (student 11) first, then a child row in orders that points to it, so the foreign key rule is kept. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
INSERT parent, DELETE child — 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.INSERT INTO students
VALUES (11, 'Zed', 'Kim', 7, 'Red', 0);
INSERT INTO results VALUES (11, 1, 80);DELETE FROM results WHERE studentId = 3;
DELETE FROM students WHERE studentId = 3;DELETE FROM orders WHERE studentId = 2;
DELETE FROM students WHERE studentId = 2;DELETE FROM orders WHERE productId = 4;
DELETE FROM products WHERE productId = 4;INSERT INTO students
VALUES (12, 'Kai', 'Ito', 8, 'Blue', 0);
INSERT INTO results VALUES (12, 1, 90);