create trigger testa on AA
for updateupdate BB Set BB.ID-2=T.ID-1,BB.Name-2=T.Name-1
from deleted T ,BB where T.ID-2=BB.ID-1
........

解决方案 »

  1.   

    create trigger AA_update
    on AA
    for update
    as 
    begin
       if exists(select * from AA a,BB b where a.[ID-1]=b.[ID-2])
           update a set a.[NAME-2]=b.[NAME-1] from BB a,updated b
                  where a.[ID-1]=b.[ID-2]   if exists(select * from AA a,CC b where a.[ID-1]=b.[ID-3])
           update a set a.[NAME-3]=b.[NAME-1] from CC a,updated b
                  where a.[ID-1]=b.[ID-3]   if exists(select * from DD a,BB b where a.[ID-1]=b.[ID-4])
           update a set a.[NAME-3]=b.[NAME-1] from DD a,updated b
                  where a.[ID-1]=b.[ID-4]
    endgo
      

  2.   

    --上面的不对,下面的测试成功。create table AA([ID-1] int,[NAME-1] varchar(20))
    go
    insert AA values(1,'aa')
    insert AA values(2,'bb')
    insert AA values(3,'cc')
    gocreate table BB([ID-2] int,[NAME-2] varchar(20))
    go
    insert BB values(1,'aa')
    insert BB values(2,'bb')
    insert BB values(3,'cc')
    go
    create table CC([ID-3] int,[NAME-3] varchar(20))
    go
    insert CC values(1,'aa')
    insert CC values(2,'bb')
    insert CC values(3,'cc')
    go
    create table DD([ID-4] int,[NAME-4] varchar(20))
    go
    insert DD values(1,'aa')
    insert DD values(2,'bb')
    insert DD values(3,'cc')
    go
    --结果
    create trigger AA_update
    on AA
    for update
    as 
    begin
       if exists(select * from AA a,BB b where a.[ID-1]=b.[ID-2])
           update b set b.[NAME-2]=a.[NAME-1] from AA a,BB b
                  where a.[ID-1]=b.[ID-2]   if exists(select * from AA a,CC b where a.[ID-1]=b.[ID-3])
           update b set b.[NAME-3]=a.[NAME-1] from AA a,CC b
                  where a.[ID-1]=b.[ID-3]   if exists(select * from AA a,DD b where a.[ID-1]=b.[ID-4])
           update b set b.[NAME-4]=a.[NAME-1] from AA a,DD b
                  where a.[ID-1]=b.[ID-4]
    endgo
    --查看
    select * from AA
    select * from BB
    select * from CC
    select * from DD
    --测试
    update AA set [NAME-1]='ee' where [ID-1]=1
    --查看
    select * from AA
    select * from BB
    select * from CC
    select * from DD
    --删除环境
    drop table AA
    drop table BB
    drop table CC
    drop table DD
      

  3.   

    create trigger AA_update
    on AA
    for update
    as 
       update BB set [NAME-2]=inserted.[NAME-1]  from BB,inserted where BB.[ID-2]=inserted.[ID-1]
       update CC set [NAME-3]=inserted.[NAME-1]  from CC,inserted where CC.[ID-3]=inserted.[ID-1]
       update DD set [NAME-4]=inserted.[NAME-1]  from DD,inserted where DD.[ID-4]=inserted.[ID-1]
      

  4.   

    --此帖中的触发器,功能更完善。
    http://community.csdn.net/Expert/topic/4426/4426003.xml?temp=.3137628
      

  5.   

    gflpower(燕赤侠) 
    像这种的,可以用关系来设置就可以了?
    给个例子?