表A
id  clu1
1   aa
2   bb
3   cc表B
clu1 clu2
aa   001
aa   002
bb   003
cc   004
bb   005
aa   006** 当修改表A的clu1时,对应的修改表B的clu1

解决方案 »

  1.   

    create trigger tri_update on ta
    for update 
    as
     update t set clu1 =i.clu1  from tb t inner join inserted i on t.clu1=i.clu1
      

  2.   

    create trigger trigger_name on A
    for update
    as
      update B set clu1=s.clu1
      from deleted as d join inserted as s on d.id=s.id
           join B on B.clu1=d.clu1
    go
      

  3.   


    -- 楼上两位的写法不是很理解。
    -- 不知道我这句有没有错?CREATE TRIGGER [Update_B] ON [dbo].[A] 
    FOR  UPDATE 
    AS
    update B set B.clum1=i.clum1 from inserted i where B.clum1=(select d.clum1 from deleted d )
      

  4.   

    create trigger tri_update on A
    for update 
    as
    update B set clu1 = I.clu1  
    from B join deleted D on B.clu1=D.clu1 
    join inserted I on D.id=I.id
    GO
      

  5.   

    你的写法,单条update没问题,如果批量update就会报错,所以推荐用联表方式。
    create trigger tri on A
    for update
    as
    if update(clu1)
    update B
    set B.clu1=i.clu1
    from inserted i,deleted d
    where i.id=d.id and B.clu1=d.clu1
    go