Recall & Review
beginner
What is a DELETE trigger in MySQL?
A DELETE trigger is a special procedure that automatically runs before or after a row is deleted from a table. It helps to perform actions like logging or checking conditions when a delete happens.
Click to reveal answer
beginner
When does a BEFORE DELETE trigger execute?
A BEFORE DELETE trigger runs just before a row is deleted from the table. It can be used to check or modify data before the deletion happens.
Click to reveal answer
intermediate
Can a DELETE trigger prevent a row from being deleted?
Yes, a BEFORE DELETE trigger can prevent deletion by signaling an error or condition that stops the delete operation.
Click to reveal answer
intermediate
Write a simple DELETE trigger that logs deleted row IDs into a log table.
CREATE TRIGGER log_delete BEFORE DELETE ON your_table FOR EACH ROW BEGIN
INSERT INTO delete_log (deleted_id) VALUES (OLD.id);
END;
Click to reveal answer
intermediate
What is the difference between BEFORE DELETE and AFTER DELETE triggers?
BEFORE DELETE triggers run before the row is deleted and can stop the deletion. AFTER DELETE triggers run after the row is deleted and cannot stop the deletion but can perform follow-up actions.
Click to reveal answer
What keyword specifies a trigger that runs before a row is deleted?
✗ Incorrect
BEFORE DELETE triggers run before the deletion happens.
Which of these can a DELETE trigger NOT do?
✗ Incorrect
After deletion, the row no longer exists, so you cannot modify it.
In MySQL, what does OLD refer to inside a DELETE trigger?
✗ Incorrect
OLD refers to the row data before it is deleted.
Which trigger timing cannot stop a delete operation?
✗ Incorrect
AFTER DELETE triggers run after deletion and cannot stop it.
What is the correct syntax to create a DELETE trigger in MySQL?
✗ Incorrect
The correct syntax uses CREATE TRIGGER with BEFORE or AFTER DELETE, ON table_name, and FOR EACH ROW.
Explain what a DELETE trigger is and when it runs in MySQL.
Think about what happens before and after a row is removed.
You got /4 concepts.
Describe how you can use a DELETE trigger to log deleted rows.
Consider saving the ID of the row before it disappears.
You got /4 concepts.