如果 BEFORE 触发器产生错误,UPDATE 是否仍会执行?

发布于 2024-07-30 10:44:59 字数 30 浏览 2 评论 0原文

如果不是,有什么办法可以从触发器中取消更新吗?

If no, is there any way to cancel the UPDATE from out of the trigger?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

身边 2024-08-06 10:45:00

编辑:如果 BEFORE 触发器失败,则 UPDATE 将被取消。

我之前的愚蠢回答是指 AFTER 触发器。 在这里以防万一有人仍然需要它:
如果是 AFTER 触发器,则如果触发器失败,则不会取消 UPDATE。 为了“取消”更新,必须使用事务,然后在出现错误时回滚事务,或者在成功时提交事务。
有关 MySQL 中事务的更多信息,请访问: http://dev .mysql.com/doc/refman/5.0/en/commit.html

EDIT: If a BEFORE trigger fails then the UPDATE is canceled.

My previous stupid answer was referring to AFTER triggers. here it is just in case anybody still needs it:
In case of AFTER trigger then the UPDATE is not canceled if a trigger fails. For "canceling" an UPDATE one has to use transactions and then ROLLBACK the transaction in case of error or commit the transaction in case of success.
more info about transactions in MySQL can be found at: http://dev.mysql.com/doc/refman/5.0/en/commit.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文