create trigger mytrg ON tableA
for insert
AS
IF (select * from table1A where aa='sun1' ) is not NULL
BEGIN
Update tableA
set bb=8,cc=7 
where aa='sun1' and bb=3 and cc=2
delete * from inserted
END

解决方案 »

  1.   

    create trigger trg_insert on tablea
    for insert
    if exist(select tablea.sun1 from tablea,inserted  where                 tablea.sun1=inserted.sun1)
             update tablea set sun1=inserted.sun1,bb=tablea.bb+inserted.bb,cc=tablea.cc+inserted.cc
    from tablea,inserted
    else
        insert into tablea (select * from inserted)
      

  2.   

    楼上的两位不知道有没有测试过自己的写法,我觉得这样写好象都有点问题。
    还是同意nononono(null,null)的意见,多加一个临时表来存放原始记录。