create trigger trInsertTest on InsertTest --取代插入操作的触发器
instead of insert
as
if @@rowcount=0
return
select * into #t from
(
select * from InsertTest
union
select * from inserted
) a
truncate table InsertTest
insert into InsertTest
select * from #t
---------------------------------------------------------------------------------------------------
create trigger trInsertTestUpdate on InsertTest --防止更新后形成重复记录的触发器
for update
as
if @@rowcount=0
return
select * into #t from
(
select * from InsertTest
union
select * from inserted
) a
truncate table InsertTest
insert into InsertTest
select * from #t
这两个触发器只适用于表记录比较少的表,如果记录条数很多,恐怕就不合适了,应该会比较损耗性能