In this article, we will review triggers in SQL Server, different types of trigger events, trigger order and NOT FOR REPLICATION in triggers. A trigger is a database object that runs automatically when an event occurs. There are three different types of events.
在本文中,我们将回顾SQL Server中的触发器,各种类型的触发器事件,触发器顺序以及触发器中的NOT FOR REPLICATION。 触发器是发生事件时自动运行的数据库对象。 有三种不同类型的事件。
- DML Events DML活动
- DDL Events DDL活动
- – Logon trigger is fired when a LOGON event occurs i.e. when a user session is being established –发生LOGON事件时即建立用户会话时,将触发登录触发器
SQL Server中的DML触发器 (DML Triggers in SQL Server)
DML triggers in SQL Server are fired when a DML event occurs. i.e. when data is inserted/ updated/deleted in the table by a user.
当发生DML事件时,将触发SQL Server中的DML触发器。 即,当用户在表中插入/更新/删除数据时。
为DML事件创建触发器 (Creating triggers for a DML event)
Let us create some sample tables and triggers in SQL Server.
让我们在SQL Server中创建一些示例表和触发器。
CREATE TABLE Locations (LocationID int, LocName varchar(100)) CREATE TABLE LocationHist (LocationID int, ModifiedDate DATETIME)
讯享网
We can create a DML trigger for a specific event or multiple events. The triggers in SQL Server(DML) fire on events irrespective to the number of rows affected.
我们可以为一个或多个特定事件创建DML触发器。 不管受影响的行数如何,SQL Server(DML)中的触发器都会触发事件。
Below is the sample syntax for creating a DML trigger for update event.
以下是为更新事件创建DML触发器的示例语法。
讯享网CREATE TRIGGER TR_UPD_Locations ON Locations FOR UPDATE NOT FOR REPLICATION AS BEGIN INSERT INTO LocationHist SELECT LocationID ,getdate() FROM inserted END

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/93159.html