首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

求多条数据批量触发触发器语句解决方法

2012-03-28 
求多条数据批量触发触发器语句现有表db1字段 iditpr1oid101119910222992033399301449940155。。。。。表db2字段

求多条数据批量触发触发器语句
现有表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 db1for updateasif update(pr1)update a set   pr2 = i.pr1from db2 a,inserted iwhere a.id = i.idand a.it = i.itand a.pid = 99and i.oid = 99go
[解决办法]
改改

SQL code
Create trigger tr_db1 on db1for update asif not update(pr1)returnupdate aset pr2=i.pr1from 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 db1for update asif not update(pr1)update aset pr2=i.pr1from inserted i join db2  a on i.ID=a.ID and i.IT=a.IT and i.oid=a.pid and i.oid=99 

热点排行
Bad Request.