Sqlserver 触发器的禁用和启用 触发器的创建


  禁用:alter table 表名 disable trigger 触发器名称
启用:alter table 表名 enable trigger 触发器名称
例如:alter table ai_track enable trigger TRI_Max_TrackID_1

CREATE TRIGGER [YourTable_1] ON [dbo].[YourTable] 
FOR INSERT
AS
UPDATE DoorTable 
Set  DoorTable.Column1=INSERTED.Column1,DoorTable.Column2=INSERTED.Column2,DoorTable.Column3=INSERTED.Column3,DoorTable.Statusstr=INSERTED.Statusstr,DoorTable.WID=INSERTED.WID,DoorTable.TrackID=INSERTED.TrackID,DoorTable.Speed=INSERTED.Speed,DoorTable.Heading=INSERTED.Heading,DoorTable.Odometer=INSERTED.Odometer
    ,NormalStatus = INSERTED.NormalStatus,AlarmStatus = INSERTED.AlarmStatus
FROM INSERTED
Where DoorTable.orderid=INSERTED.orderid -- and INSERTED.Column3>DoorTable.Column3 and INSERTED.Column3<dateadd(minute,100,getdate())

 

CREATE TRIGGER TR_TimeCardUpdateSSIs
ON TimeCard
FOR UPDATE
AS
BEGIN
  INSERT INTO DataGenerator.dbo.SSIUpdate(appName, empID, lastUPdate)
  SELECT 'TimeSheets', U.supervisorID, GETDATE()
  FROM Inserted AS I
  INNER JOIN Emp.dbo.Users AS U
  ON I.empID = U.empID
END

你可能感兴趣的:(sqlserver)