0
我有2列的表:id和名稱。需要在該表中記錄更改時觸發其他表中更新後的值。創建更新觸發器
我有2列的表:id和名稱。需要在該表中記錄更改時觸發其他表中更新後的值。創建更新觸發器
喜歡的東西:
CREATE TRIGGER [dbo].[trigger_tablename] -- replace 'tablename' with your table name
ON [dbo].[tablename] FOR UPDATE -- replace 'tablename' with your table name
AS
BEGIN
insert into T_tablename_Monitor -- replace 'tablename' with your table name
select NewID(),ID, Name,'After Update',SUSER_SNAME(), getdate() from inserted
END
監控表可能看起來像:
CREATE TABLE [dbo].[T_tablename_Monitor](-- replace 'tablename' with your table name
[Row_ID] [varchar](36) NOT NULL,
[ID] [varchar](30) NOT NULL, -- replace with your type
[Name] [varchar](50) NULL, -- replace with your type
[Action] [varchar](50) NOT NULL,
[UserName] [varchar](100) NOT NULL,
[CTime] [datetime] NOT NULL
) ON [PRIMARY]
Here是如何創建一個更新觸發器