1

I want to have the following 3 triggers:

#START TRIGGER
delimiter $$
CREATE TRIGGER `lastedited` AFTER UPDATE ON `eng-jap`
FOR EACH ROW
BEGIN
UPDATE `mrhowtos_main`.`eng` 
SET `english` = new.eng WHERE `english` = old.eng;
UPDATE `mrhowtos_main`.`jap` 
SET `japanese` = new.jap WHERE `japanese` = old.jap;
END;
$$


#START TRIGGER
delimiter $$
CREATE TRIGGER `lastedited2` AFTER UPDATE ON `eng`
FOR EACH ROW
BEGIN
UPDATE `mrhowtos_main`.`eng-jap` 
SET `eng-jap`.`eng` = new.english WHERE `eng-jap`.`eng` = old.english;
END;
$$


#START TRIGGER
delimiter $$
CREATE TRIGGER `lastedited3` AFTER UPDATE ON `jap`
FOR EACH ROW
BEGIN
UPDATE `mrhowtos_main`.`eng-jap` 
SET `eng-jap`.`jap` = new.japanese WHERE `eng-jap`.`jap` = old.japanese;
END;
$$

but before i even create them i see that there will be this infinite looping of the triggers as soon as any of the tables get updated. Basically i do not want the triggers UPDATE to "trigger" the other triggers. How do I do that?

Michael Durrant
  • 93,410
  • 97
  • 333
  • 497
user1397417
  • 708
  • 4
  • 11
  • 34
  • this is exactly why triggers are an anti-pattern and [evil](http://stackoverflow.com/questions/3048340/when-are-database-triggers-bad) –  May 16 '12 at 14:35
  • 2
    Small trick - http://stackoverflow.com/questions/9570204/how-to-avoid-circular-trigger-dependencies-in-mysql – Devart May 16 '12 at 14:40
  • 1
    @JarrodRoberson - so triggers are an antipattern because what, every possible construct in languages out there are supposed to cure developer's stupidity or am I missing something? – Mjh Jul 26 '16 at 15:11

0 Answers0