一张表上的两个触发器sql server

发布于 2024-09-11 04:15:56 字数 89 浏览 1 评论 0原文

我的数据库中的一张表有两个触发器。一种是插入触发器,另一种是更新后触发器。插入触发器将用值更新表。我的问题是这样的;更新触发器是否有可能在插入执行其工作的同时触发?

I have two triggers on one of the tables in my database. One is for insert trigger and the other is an after update trigger. The insert trigger will update the table with values. My question is this; Is it possible that that the update trigger is firing at the same time that the insert is doing its job?

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

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

发布评论

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

评论(2

三生路 2024-09-18 04:15:56

FOR INSERT 触发器将INSERT 语句上触发。 FOR UPDATE 触发器将UPDATE 语句上触发。当然,如果您的插入触发器执行任何 UPDATE 语句,那么它将触发更新触发器,反之亦然。

您的 UPDATE 触发器不会因 INSERT 语句而触发(上面的 update-within-trigger 情况除外),但是当然您仍然需要设计并发性,因为它是两个不同的用户可以同时运行两个不同的操作 - 一个 INSERT 和一个 UPDATE

A FOR INSERT trigger will fire only on INSERT statements. A FOR UPDATE trigger will fire only on UPDATE statements. Of course, if your insert trigger executes any UPDATE statements then it will fire the update trigger, and vice versa.

Your UPDATE trigger won't fire for an INSERT statement (excepting the update-within-trigger case above), but of course you still have to design for concurrency, since it's possible for two different users to be running two different operations at the same time - one INSERT and one UPDATE.

很快妥协 2024-09-18 04:15:56

如果您的插入触发器对表进行了更新,则将调用更新触发器。如果一个触发器触发另一个触发器,则称为“递归触发器”。

可以为整个服务器禁用递归触发器:

sp_configure 'nested_triggers', 0
go
reconfigure

或为一个数据库禁用递归触发器:

alter database yourdb set recursive_triggers off

If your insert trigger does an update to the table, the update trigger will be called. If a trigger triggers another trigger, it's called a "recursive trigger".

Recursive triggers can be disabled for an entire server:

sp_configure 'nested_triggers', 0
go
reconfigure

Or for one database:

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