I have a table that stores parent and child records in it.
I was trying to create a trigger that would delete all child records when the parent is deleted:
Delete From tbl Where ParentId = OLD.Id
While I can save the trigger successfully, when deleting I get this error:
ERROR 1442: Can’t update table ‘tbl′ in stored function/trigger because it is already used by statement which invoked this
What am I doing wrong?
It appears that this is not possible:
You cannot DELETE rows in the table that activated trigger.
Some other options you might think about: