--假设a,b字段都为int型,如果类型不对,自己更改 create trigger my_trig on tb for update as begin declare @a1 as int declare @a2 as int declare @b1 as int declare @b2 as int select @a1 = a , @b1 = b from deleted select @a2 = a , @b2 = b from inserted if @a1 <> @a2 and @b1 <> @b2 --这两句,自己选一句,看哪个合适? update tb set c = @b2 where 关键字 = (select 关键字 from inserted) update tb set c = @b2 where a = @a2 and b = @b2 end go
BEGIN
IF UPDATE(A) AND UPDATE(B)
..
END
if update(A) and update(B)
for update
as
begin
if update(a) and update(b) then
update tb c=b from tb,deleted d where tb.a=d.a and tb.b = d.b
end
for update
as
begin
if update(a) and update(b)
update tb c=b from tb,deleted d where tb.a=d.a and tb.b = d.b
end
create trigger my_trig on tb for update
as
begin
declare @a1 as int
declare @a2 as int
declare @b1 as int
declare @b2 as int
select @a1 = a , @b1 = b from deleted
select @a2 = a , @b2 = b from inserted
if @a1 <> @a2 and @b1 <> @b2
--这两句,自己选一句,看哪个合适?
update tb set c = @b2 where 关键字 = (select 关键字 from inserted)
update tb set c = @b2 where a = @a2 and b = @b2
end
go