I have table "A" in MySQL. It has some references with cascade deleting to some other tables ("B", "C", "D" ...). I need to use a trigger when something deletes from "A". This trigger works when I delete records from "A" directly. But it doesn't work with cascade deleting. Does any version of MySQL exist where my trigger will work with cascade deleting? Or, maybe, there is another way to call
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
From http://dev.mysql.com/doc/refman/5.6/en/innodb-restrictions.html
Cascaded foreign key actions do not activate triggers
In other words, you cannot use the trigger with cascaded deleting.
回答2:
To summarize the answers from @Niel de Wet and @Browny Lin:
- Sadly cascaded deletes do not activate triggers in MySQL.
- One solution is to not use cascading deletes but instead implement the automatic delete via another trigger.
回答3:
Let me share how I've been "fixing" this issue from the first day I discovered it existed. I copy the trigger from the cascaded table into the first table that's deleted directly. It just works.
A lot of times it's a matter of copy/paste, and occasionally it requires extensive re-writing of the code.
The best part is, when Oracle finally fixes this Bug you only have remove the trigger code from the said table. Voila!