4
votes

I have two (InnoDB) tables with triggers for UPDATE, INSERT and DELETE. They work fine if I work directly on the tables. Further I have a foreign key constraint when I delete a row in tableA all rows in tableB referenced by tableA.id get also deleted. That also works but the problem is:

A DELETE on tableA triggers the DELETE-trigger for tableA. Then the constraint deletes rows at tableB but no DELETE-triggers for tableB get called. Why? Do constraints do not trigger triggers?

Thanks.

(Triggers are AFTER DELETE. Tried also with BEFORE DELETE without success.)

1
Cascading deletes should fire the triggers on the other table. What version of MySQL are you using? - landons
I am using 5.5.29. And on tableB I have CONSTRAINT cname FOREIGN KEY (idA) REFERENCES tableA (id) ON DELETE CASCADE ON UPDATE CASCADE, - Lorenz
@landons: it's clearly stated in the manual that this is not the case. - a_horse_with_no_name
Hmm, I stand corrected. I was pretty sure that it worked in an older version of MySQL... - landons

1 Answers

8
votes

Triggers aren't fired if the delete is caused by a foreign key.

From the manual

Triggers currently are not activated by foreign key actions.