if not exists(select *from deleted)--如果是新增if(select count(*) from deleted)>0 and (select count(*) from inserted)>0--如果是更新你可以这样判断是新增或者更新,然后再定义一个变量,用来得到触发的时间,再更新到原表里面
create trigger my_trig on A for insert ,update as begin update A set a5 = getdate() from A t ,inserted i where t.a1 = i.a1 and t.a2 = t.a2 and t.a3 = i.a3 and t.a4 = i.a4 end go
and (select count(*) from inserted)>0--如果是更新你可以这样判断是新增或者更新,然后再定义一个变量,用来得到触发的时间,再更新到原表里面
as
begin
update A set a5 = getdate() from A t ,inserted i
where t.a1 = i.a1 and t.a2 = t.a2 and t.a3 = i.a3 and t.a4 = i.a4
end
go