如题:  a表字段: Id,auditStatus        b表字段: ID,aID,ischange  
                 1,  0                          1, 1 , 0
                 3,  0                          2, 3 , 0
a表 id,相b表aID相关联.. 请问当我a表里的auditStatus更新为1时,怎么触发b表中与a表相关联的数据 ischange要更新 1 

解决方案 »

  1.   

    create trigger tg_test on a
    for update
    as
    update b set 
        ischange=1
    from inserted i
    where i.id=b.aid
      and i.auditStatus=1
    go
      

  2.   

    create trigger f on a
    for update
    as
    update b set ischange=1  from inserted i where i.id=b.aid and i.auditstatus=1
    go
      

  3.   

    create trigger tg_test on a
      for update
       as
       update b set 
         ischange=1
        from inserted i,b b
          where i.id=b.aid
               and i.auditStatus=1
    go
      

  4.   

    create trigger tg_update_a on a
    for update
    as
    update b set ischange=1
    from inserted a
    where a.id=b.aid and a.auditStatus=1
    go