创建仅影响当前行的 MySQL 触发器
我想设置一个触发器,仅影响插入的行,而不影响其他行。
所以我需要与每一行不同的东西。这是我现在所拥有的。
CREATE TRIGGER mytrigger BEFORE INSERT ON student
FOR EACH ROW SET @starost =new.starost+2;
I want to set a trigger that effects only the row that is inserted, not the other rows.
So I need something different than for each row. Here is what I have now.
CREATE TRIGGER mytrigger BEFORE INSERT ON student
FOR EACH ROW SET @starost =new.starost+2;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
INSERT
触发器中的FOR EACH ROW
仅影响插入的行。它将处理多于一行的情况(因此名称暗示它处理多行)将是在批量插入上,就像使用 INSERT 时一样。 。 .SELECT 语法。FOR EACH ROW
in anINSERT
trigger only affects the inserted rows. The case where it would handle more than one row (and as such the name implies it handles more than one row) would be on a bulk insert like when using theINSERT. . .SELECT
syntax.您几乎已经完成了:
它会在插入之前向
starost
字段添加两个You nearly had it:
It will add two to the
starost
field before insertion