34,838
社区成员




create trigger tr_tb on tb after insert,update
as
if Update(f1)
update tb
set f3=a.f1*a.f2 from tb a inner join inserted b on a.id=b.id
WHERE b.f1 IS NOT NULL AND b.f2 IS NOT null
go
create trigger trig_test on tb
instead of update
as
set nocount on
if update(F1)
begin
if exists(select 1 from deleted where F1 is null and F2 is null)
begin
update tb set F3=(select F1*F2 from inserted)
end
end
--try
create trigger trig_test on tb
for update
as
set nocount on
if update(F1)
begin
if exists(select 1 from deleted where F1 is null and F2 is null)
begin
update tb set F3=(select F1*F2 from inserted)
end
end
if object_id('tb','U') is not null
drop table tb
go
create table tb
(
id int,
f1 int,
f2 int,
f3 int
)
go
insert into tb
select 1,1,2,2
go
if object_id('tr_tb','TR') is not null
drop trigger tr_tb
go
create trigger tr_tb on tb after insert,update
as
if Update(f1)
update tb set f3=a.f1*a.f2 from tb a inner join inserted b on a.id=b.id
go