04 Try it yourself Interactive

Delete a department three ways

The same seven statements against the same two tables, with one word changed in CREATE TABLE. Pick the referential action, then step through: a child row is inserted pointing at a department that does not exist, the same row is inserted pointing at one that does, and then the department two employees belong to is deleted. The last two steps start again with dept_id declared NOT NULL and run the delete once more, which is where SET NULL comes apart. Nothing plays on its own: Next, Back and Reset, or the arrow keys.

ON DELETE CASCADE
two tables · one foreign key
Each block is one table, with its column names on the labelled row. Rose marks a row this step refused or changed, green marks a row it accepted, and the note on the right says why.
Press Next to begin. Each press advances the run by one step.


      
Department rows
Employee rows
Statements accepted0
Statements refused0
step 0 / 0