当先锋百科网

首页 1 2 3 4 5 6 7

 

GO

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

 

Create trigger [dbo].[tri_device]

on [dbo].[Device]

for insert,update,delete

as

begin

if EXISTS(SELECT 1 FROM inserted) AND NOT EXISTS(SELECT 1 FROM deleted)

insert into RealData(DtuId,Val,RcvTime)

select DtuId,'0',getdate() from inserted;

IF EXISTS(SELECT 1 FROM inserted) AND EXISTS(SELECT 1 FROM deleted)

update RealData set DtuId=a.DtuId from inserted a

IF NOT EXISTS(SELECT 1 FROM inserted) AND EXISTS(SELECT 1 FROM deleted)

delete from RealData where DtuId=(select a.DtuId from deleted a)

end;

转载于:https://www.cnblogs.com/umlzhang/p/9330657.html