这个是得到的结果
表table1 , 表table2
id anum id bnum --bnum bit字段
1 11 1 1
2 222 2 1
3 33 3 0
因为我只接收到id=2的参数。从而触发了table2的更新。
表table1 , 表table2
id anum id bnum --bnum bit字段
1 11 1 1
2 222 2 1
3 33 3 0
因为我只接收到id=2的参数。从而触发了table2的更新。
insert into taba
select 1,'aa1','11' union
select 2,'aa2','22'
insert into tabb
select 1,'bb1','1' union
select 2,'bb2','0'
CREATE TRIGGER [TRI_up] ON [taba]
FOR UPDATE
AS
if update (amun)update 表b set bmun='1'
from tabb b inserted c where b.id=c.id
从inserted里提出修改的ID
on table1
for update
asupdate table2
set bnum=1
from inserted i
where i,id-table2,idgo
insert into taba
select 1,'aa1','11' union
select 2,'aa2','22'
insert into tabb
select 1,'bb1','222' union
select 2,'bb2','333'
CREATE TRIGGER [TRI_up] ON [taba]
FOR UPDATE
AS
if update (amun)update tabb set bmun='1'
from tabb b,inserted c where b.id=c.idUPDATE TABA SET amun='99' where id=1
on table1
for update
asupdate table2
set bnum=1
from inserted i
where i.id=table2.idgo
---建表
create table taba (id int,aname varchar (10),amun varchar (10))create table tabb (id int,bname varchar (10),bmun bit)---插入数据
insert into taba
select 1,'aa1','11' union
select 2,'aa2','22' union
select 3,'aa3','33'
insert into tabb
select 1,'bb1',1 union
select 2,'bb2',0 union
select 3,'bb3',0
---对taba表建立触发器CREATE TRIGGER [TRI_up] ON [taba]
FOR UPDATE
AS
if update (amun)update tabb set bmun='1'
from tabb b,inserted c where b.id=c.id
----测试UPDATE TABA SET amun='222' where id=2
---结果select * from tabb
----------
id bname bmun
-- ----- ----
1 bb1 1
2 bb2 1
3 bb3 0