日期:2014-05-17  浏览次数:20404 次

SQL 2000触发器
tb1

id  年   完成  name
 1 2013  0
 2 2012  0
 3 2011  0
 4 2011  0
 5 2012  0
 6 2013  0

tb2

id  年  name
 1 2013  name1
 2 2012  name2
 3 2011  name3
 4 2011  name4
 5 2012  name5
 6 2013  name6

想得到一个触发器,当tb1的完成字段有变化的时候,从tb2得到id、年相对应的name信息进行更新

------解决方案--------------------
create trigger tr_tb1
on tb1
for update
as
begin
   if update(完成)
     update tb1 set name = a.name
      from tb2 a where tb1.id = a.id 
     and tb1.年 = a.年
end