FOR 和 AFTER 触发器之间的区别?
FOR
和 AFTER
触发器之间有什么区别?
What's the difference between FOR
and AFTER
triggers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
FOR
和 AFTER
触发器之间有什么区别?
What's the difference between FOR
and AFTER
triggers?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
没有什么区别,他们做同样的事情。
与
INSTEAD OF
触发器不同,它在插入之前触发,而不是插入,并且可以在视图上使用,以便将适当的值插入到基础表中。There is no difference, they do the same thing.
Is the same as
An
INSTEAD OF
trigger is different, and fires before and instead of the insert and can be used on views, in order to insert the appropriate values into the underlying tables.@Ben 绝对正确。
这是MSDN文章 探索SQL Server 触发器
文章中的一段话:
@Ben is absolutely right.
Here is MSDN article Exploring SQL Server Triggers
A paragraph from the article:
AFTER 指定仅当触发 SQL 语句中指定的所有操作均已成功执行时才触发 DML 触发器。在此触发器触发之前,所有引用级联操作和约束检查也必须成功。
当 FOR 是唯一指定的关键字时,AFTER 是默认值。
不能在视图上定义 AFTER 触发器。
代替
指定执行 DML 触发器而不是触发 SQL 语句,因此覆盖触发语句的操作。不能为 DDL 或登录触发器指定 INSTEAD OF。
https://learn.microsoft.com /en-us/sql/t-sql/statements/create-trigger-transact-sql
AFTER specifies that the DML trigger is fired only when all operations specified in the triggering SQL statement have executed successfully. All referential cascade actions and constraint checks also must succeed before this trigger fires.
AFTER is the default when FOR is the only keyword specified.
AFTER triggers cannot be defined on views.
INSTEAD OF
Specifies that the DML trigger is executed instead of the triggering SQL statement, therefore, overriding the actions of the triggering statements. INSTEAD OF cannot be specified for DDL or logon triggers.
https://learn.microsoft.com/en-us/sql/t-sql/statements/create-trigger-transact-sql