避免在 mysql 中的每一行 [英] avoiding for each row in mysql

查看:48
本文介绍了避免在 mysql 中的每一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道是否有办法在 mysql 查询中不使用 FOR EACH ROW 语法?

Does anyone know if there a way to not have the FOR EACH ROW syntax in a mysql query?

也许是一种解决方法?

我需要使用 after insert 触发器,但应用程序在插入过程中多次插入.

I need to use an after insert trigger but the application insert multiple times as part of an insert.

因此触发器以复合方式将数据视为每个插入的一部分.

So the trigger sees the data in a compounding fashion as part of every insert.

推荐答案

AFTER INSERT 触发器定义中需要 FOR EACH ROW 语法.MySQL 仅支持行级"触发器.MySQL 不支持 DML 操作的语句级别"触发器.这是设计使然.

The FOR EACH ROW syntax is required in an AFTER INSERT trigger definition. MySQL supports "row level" triggers only. MySQL doesn't support "statement level" triggers for DML operations. This is by design.

有解决方法吗?

不,没有解决方法.AFTER INSERT FOR EACH ROW 触发器将为插入的每一行触发.是否有十几个单独的 INSERT 语句每个插入一行都没有关系,或者是否有一个 INSERT 语句插入十几个行都没有关系.将为每一行触发触发器.

No, there is no workaround. An AFTER INSERT FOR EACH ROW trigger is going to get fired for every row that gets inserted. It doesn't matter whether there's a dozen separate INSERT statements that each insert a single row, or whether there's a single INSERT statement that inserts a dozen rows. The trigger will be fired for each row.

您可以在触发器内进行比较或检查,然后您可以有条件地围绕触发器内的部分代码进行分支.但是,对于插入的每一行,都无法绕过 AFTER INSERT 触发器的触发.

Within the trigger you can compare this or check that, and then you can conditionally branch around portions of code within the trigger. But there's no way to bypass the firing on an AFTER INSERT trigger for every row that gets inserted.

这篇关于避免在 mysql 中的每一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆