MySQL - Triggers - after I created the trigger and ran delete query, it gave me
ID: 3800377 • Letter: M
Question
MySQL - Triggers - after I created the trigger and ran delete query, it gave me error code 1054: Unknown column 'Bird.btag' in 'where clause'
The CTO has observed that some of the lesser-paid application developers seem incapable of following instructions. Instead of deleting birds at the User level in the type hierarchy, i.e., by targeting the User table, some of the developers continue to delete birds at the Bird level. As a result, the CTO has asked you to safeguard the database by creating a row-level trigger on the Bird table that, if a Bird is deleted, cascades the deletion to the User table.
DELIMITER $$
CREATE TRIGGER deletion AFTER DELETE ON Bird
FOR EACH ROW
BEGIN
DELETE FROM User Where User.tag = Bird.btag;
END
Explanation / Answer
CREATE TRIGGER deletion AFTER DELETE ON Bird
FOR EACH ROW
BEGIN
DELETE FROM User Where User.tag =(SELECT btag FROM bird Where btag = old.btag);
END
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.