CREATE TRIGGER Tri_Ad_Group ON [dbo].[Ad_Group] FOR UPDATE,INSERT,DELETE AS Declare @InsertedCount Int Declare @DeletedCount Int Set @InsertedCount = ( select Count(*) from Inserted) Set @DeletedCount = ( select Count(*) from Deleted) if (@InsertedCount > 0) begin Insert Into Ad_GroupLog(ID,Action,UpdUser,UpdDateTime) select ID,Case when ( @DeletedCount > 0) then 'Update' Else 'Insert' end,Current_User,Current_TimeStamp from Inserted end else if ( @DeletedCount > 0) begin Insert into Ad_GroupLog(ID,Action,UpdUser,UpdDateTime) select ID,'Delete',Current_User,Current_TimeStamp from Deleted end 做个参考好了,这个是添加修改删除都有的一个我写的你看看吧
create trigger a_tri before insert or update or delete on a for each row begin if inserting then insert into b values(:new.colname,...); elsif updating then update b set .... where id=:new.id; else delete from b where id=:old.id; end if; end; /
FOR UPDATE,INSERT,DELETE
AS
Declare @InsertedCount Int
Declare @DeletedCount Int
Set @InsertedCount = ( select Count(*) from Inserted)
Set @DeletedCount = ( select Count(*) from Deleted)
if (@InsertedCount > 0) begin
Insert Into Ad_GroupLog(ID,Action,UpdUser,UpdDateTime) select ID,Case when ( @DeletedCount > 0) then 'Update' Else 'Insert' end,Current_User,Current_TimeStamp from Inserted
end
else if ( @DeletedCount > 0) begin
Insert into Ad_GroupLog(ID,Action,UpdUser,UpdDateTime) select ID,'Delete',Current_User,Current_TimeStamp from Deleted
end
做个参考好了,这个是添加修改删除都有的一个我写的你看看吧
before insert or update or delete on a
for each row
begin
if inserting then
insert into b values(:new.colname,...);
elsif updating then
update b set .... where id=:new.id;
else
delete from b where id=:old.id;
end if;
end;
/