Whether a trigger is executed for each row in the "insert duplicate key update" request before INSERT is run

How it works? Does mysql call before running INSERT only in case of insertions, or every time an insert or update occurs, if the query being executed looks like this:

INSERT INTO tSomething VALUES (...) ON DUPLICATE KEY UPDATE ......

I want to update the column value depending on other col values ​​when inserting a row. However, I do not want this behavior for updates. The query, which will always be executed, will be as indicated above. For this, I chose INSERT AFTER. However, I cannot update col using AFTER INSERT TRIGGER as

SET NEW.score = NEW.score1 + NEW.score2;

I read somewhere that before the INSERT trigger is triggered, in this case it would be possible to trigger the triggers every time the request is executed. It's true? If so, how to solve this problem with a trigger.

+1
source share
1 answer

Does mysql trigger AFTER INSERT only in case of insertions or every time an insert or update occurs.

To the right of the manual :

a trigger BEFORE INSERT is activated for each row, followed by either an AFTER INSERT trigger or triggers BEFORE UPDATING AND AFTER UPDATING, depending on whether there was a duplicate key for the row

I'm not sure what exactly you need.

" , , " - . AFTER INSERT, , UPDATE. , UPDATE, INSERT.

0

Source: https://habr.com/ru/post/1670476/


All Articles