create trigger in_tri on tb
for insert
as
if (select * from inserted i,tb,b where (i.a=b.a and i.b=b.b))
update tb set z=max(z)+1 from inserted i where (i.a=b.a and i.b=b.b)
else
update tb setz=1 where (i.a=b.a and i.b=b.b)
go

解决方案 »

  1.   

    create trigger in_tri on tb
    for insert
    as
    if (select * from inserted i,tb,b where (i.a=b.a and i.b=b.b))
    update tb set z=max(z)+1 from inserted i where (i.a=b.a and i.b=b.b)
    else
    update tb set z=1 where (i.a=b.a and i.b=b.b)
    go
      

  2.   

    create trigger in_tri on tb
    for insert
    as
    if (select * from inserted i,tb,b where (i.a=b.a and i.b=b.b))
    update tb set z=max(z)+1 from inserted i where (i.a=b.a and i.b=b.b)
    elseupdate tb set z=1 from inserted i where (i.a=b.a and i.b=b.b)go
      

  3.   

    create trigger in_tri on tb
    for insert
    as
    if (select * from inserted i,tb,b where (i.a=b.a and i.b=b.b))
    update tb set z=max(z)+1 from inserted i where (i.a=b.a and i.b=b.b)
    else
    update tb set z=1 where (i.a=b.a and i.b=b.b)
    go