是否对“插入重复键更新”中的每一行执行 BEFORE INSERT 触发器?询问
这是如何运作的 ?如果要运行的查询如下“
INSERT INTO tSomething VALUES (...) ON DUPLICATE KEY UPDATE ......
我想要插入行时根据其他列的值更新列的值但是,我不希望这种更新行为始终是我选择的 INSERT 。但是,我无法使用 AFTER INSERT TRIGGER as
SET NEW.score = NEW.score1 + NEW.score2 更新列;
我在某处读到,在这种情况下 BEFORE INSERT 触发器将允许每次在上面时触发触发器查询被执行。这是真的吗?如果是,我如何使用触发器解决这个问题。
How does this work ? Does mysql invoke BEFORE INSERT trigger only in case of inserts or everytime an insert or update happens if the query to be run is as follows "
INSERT INTO tSomething VALUES (...) ON DUPLICATE KEY UPDATE ......
I want to update a column's value depending upon other col's values when inserting a row. However, I don't want this behaviour for updates. The query which will be executed always would be the one mentioned above. I chose INSERT AFTER for this. However, I can't update a col using AFTER INSERT TRIGGER as
SET NEW.score = NEW.score1 + NEW.score2 ;
I read somewhere that BEFORE INSERT trigger in this case would allow triggers to be fired everytime when above query is executed. Is this true ? If yes, how do I solve this problem using a trigger.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正确 来自手册:
我不确定您到底在做什么。
“但是,我不希望这种更新行为”这句话让我感到困惑。如果您唯一拥有的是 AFTER INSERT 触发器,那么当您运行 UPDATE 语句时它不会被触发。如果您的语句更新一行,它将触发 UPDATE 触发器,而不是 INSERT 触发器。
Right from the manual:
I'm not sure what exactly you are after.
The sentence "However, I don't want this behaviour for updates" confuses me somehow. If the only thing you have is an AFTER INSERT trigger, then it will not be fired if you run an UPDATE statement. And if your statement updates a row, it will fire an UPDATE trigger, not your INSERT trigger.