日期:2014-05-18  浏览次数:20435 次

求多条数据批量触发触发器语句
现有表db1 字段 id it pr1 oid
  1 01 11 99
  1 02 22 99
  2 03 33 99
  3 01 44 99
  4 01 55  
  。。。。。

  表db2 字段 id it pr2 pid  
  1 01 11 99
  1 02 22 99
  2 03 33 99
  3 01 44 99
  4 01 0
  。。。。。。

当表db1中PR1记录值更新时,对应更新表DB2中pr2值,当且 id it 值相等 pid=oid=99时,对应触发更新DB2中PR2值
触发器该怎么写?

谢谢

 

------解决方案--------------------
SQL code
create trigger tr_db1_update 
on db1
for update
as

if update(pr1)
update a set
   pr2 = i.pr1
from db2 a,inserted i
where a.id = i.id
and a.it = i.it
and a.pid = 99
and i.oid = 99

go

------解决方案--------------------
改改

SQL code
Create trigger tr_db1 on db1
for update 
as
if not update(pr1)
return
update a
set pr2=i.pr1
from inserted i 
inner join db2 as a on i.ID=a.ID and i.IT=a.IT and i.oid=a.pid and i.oid=99

------解决方案--------------------
SQL code
Create trigger test on db1
for update 
as
if not update(pr1)
update
 a
set
 pr2=i.pr1
from
 inserted i 
join
 db2  a on i.ID=a.ID 
and
 i.IT=a.IT and i.oid=a.pid and i.oid=99