一张表上的两个触发器sql server
我的数据库中的一张表有两个触发器。一种是插入触发器,另一种是更新后触发器。插入触发器将用值更新表。我的问题是这样的;更新触发器是否有可能在插入执行其工作的同时触发?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
FOR INSERT
触发器将仅在INSERT
语句上触发。FOR UPDATE
触发器将仅在UPDATE
语句上触发。当然,如果您的插入触发器执行任何 UPDATE 语句,那么它将触发更新触发器,反之亦然。您的
UPDATE
触发器不会因INSERT
语句而触发(上面的 update-within-trigger 情况除外),但是当然您仍然需要设计并发性,因为它是两个不同的用户可以同时运行两个不同的操作 - 一个INSERT
和一个UPDATE
。A
FOR INSERT
trigger will fire only onINSERT
statements. AFOR UPDATE
trigger will fire only onUPDATE
statements. Of course, if your insert trigger executes anyUPDATE
statements then it will fire the update trigger, and vice versa.Your
UPDATE
trigger won't fire for anINSERT
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 - oneINSERT
and oneUPDATE
.如果您的插入触发器对表进行了更新,则将调用更新触发器。如果一个触发器触发另一个触发器,则称为“递归触发器”。
可以为整个服务器禁用递归触发器:
或为一个数据库禁用递归触发器:
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:
Or for one database: