日期:2014-05-17  浏览次数:20449 次

触发器的简单应用
需求:表A,有两个字段ID,a;某一条记录有update操作时,如果其字段a>10,则把这条记录插入到B表中(B中也有ID这个字段,如果已经存在这个ID的了,则不执行插入操作,否则执行)
------解决方案--------------------
create trigger triTest
on A
for update
as
begin
  insert b
  select xxx,xxx from inserted a
  where not exists(select * from b b where a.id=b.id)
    and a.id>10
end