Answer the question
In order to leave comments, you need to log in
How to track the call of a pair of triggers during Replace?
When performing a REPLACE in Mysql, two actions are actually done - deleting a row if it exists by a unique key, and inserting a new one. Accordingly, two triggers After Delete and After Insert are called independently of each other.
Is there any way to distinguish within the trigger procedure that it was called by the Replace operation and that there is a "colleague" for it that has already been or will be called? Or at least distinguish a trigger call in this way from calls with INSERT and DELETE operations?
Answer the question
In order to leave comments, you need to log in
You cannot determine inside the body of a trigger whether it was called INSERT or REPLACE. You can try to write flags to session variables inside the trigger body:
CREATE TRIGGER after_delete AFTER delete on table FOR EACH ROW BEGIN
SET @deleteTriggerExecuted = 1;
END;
CREATE TRIGGER after_insert AFTER INSERT on class FOR EACH ROW BEGIN
IF @deleteTriggerExecuted = 1 THEN
-- триггер after_delete был вызван
END IF;
END;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question