MySQL after insert and after trigger update
I have two tables t1 and t2. I created two triggers tr1 after inserting on t1 and tr2 after updating to t2. in both tables i m updates table t2. therefore, it throws an error saying that table t2 is already being updated in another trigger, so it cannot update it again.
Please let me know if anyone has encountered this type of problem and fixed it.
Thanks in advance! MySQL DBA.
a source to share
If you want to change the data being updated or inserted, you must use the ADDIT and / or ADD INSERT trigger and then use a new alias (it refers to the row that is being inserted or the row how it will make sure the update is applied) - you can actually change the entered fields. ALID OLD refers to the row before the update is applied, or the row before it is deleted (in triggers that are fired on deletion).
So, you probably need something like this for a tr2 trigger:
DELIMITER $$
CREATE TRIGGER tr2 BEFORE UPDATE ON t2
FOR EACH ROW BEGIN
SET NEW.field1 = some_value_you_want_to_set_it_to;
END;
$$
DELIMITER ;
Because in a trigger, you cannot UPDATE a table that is already being updated, that is correct.
a source to share