--计算列也可以 create table tb(a int,b as a) goinsert into tb(a) select 1 goupdate tb set a=2 goselect * from tbdrop table tb
create table a(id int, data int) insert a select 1,2 union all select 3,5create trigger aa on a for update as begin update a set data=inserted.id from a,inserted where a.id=inserted.id end
create table tb(a int,b int) insert into tb select 1,1 insert into tb select 2,2 insert into tb select 4,4 gocreate trigger cfq on tb for update asif @@rowcount=0 returnupdate tb set b=b.a from tb a,inserted b where a.a=b.a goupdate tb set a=2 where a=1 update tb set a=3 where a=2 goselect * from tbdrop trigger cfq drop table tb--触发器
CREATE TRIGGER [up] ON [dbo].[temptable] FOR UPDATE AS if update(name1) update temptable set name2=Inserted.name1 from temptable,Inserted where temptable.id=Inserted.id
create table tb(a int,b as a)
goinsert into tb(a) select 1
goupdate tb set a=2
goselect * from tbdrop table tb
insert a select 1,2
union all select 3,5create trigger aa on a
for update
as
begin
update a set data=inserted.id from a,inserted where a.id=inserted.id
end
insert into tb select 1,1
insert into tb select 2,2
insert into tb select 4,4
gocreate trigger cfq on tb
for update
asif @@rowcount=0 returnupdate tb set b=b.a from tb a,inserted b where a.a=b.a
goupdate tb set a=2 where a=1
update tb set a=3 where a=2
goselect * from tbdrop trigger cfq
drop table tb--触发器
FOR UPDATE
AS
if update(name1)
update temptable set name2=Inserted.name1 from temptable,Inserted where temptable.id=Inserted.id