我两给表:
1 products表,其中有一个字段是产品的id号,为:productid,这个字段是主键
如:
  productid
     a
     b
     c
     d
     e
2 还有一个表:assemtree 其中有一个字段是:childproductid,这里面得值可以重复出现的。
如:
  childproductid
       a
       a
       b
       c
       d
       d
       e我想在products表中建立一个触发器,当productid的值改变的时候,assemtree表中的childproductid的值也同样改变改变后的products表:productid   (a变成了f)
     f
     b
     c
     d
     e
改变后的assemtree表:
childproductid  (两个a都变成了f)
       f
       f
       b
       c
       d
       d
       e
请高手指导,谢谢!!!

解决方案 »

  1.   

    create trigger trg_A on A for update
    as
    begin
      update B 
      set 
          childproductid=i.productid 
      from 
          inserted i,deleted d,B 
      where 
          d.productid=B.productid
    end
    go
      

  2.   

    只适用于一次更新一条 products 表记录的情形。
    create trigger trg_A on products for update
    as
    begin
      update B 
      set 
          childproductid=i.productid 
      from 
          inserted i,deleted d,assemtree B 
      where 
          d.productid=B.productid
    end
    go
      

  3.   


    create trigger gg on products
    for update
    as
    if update(productid )
    update assemtree
    set childproductid =i.productid
    from  assemtree a,inserted i,deleted d
    where a.childproductid=d.productid 
    ??
      

  4.   

    create  tigger f on products for update
    as
    begin
       update
          b
       set
         childproductid=i.productid 
       from
         inserted i,deleted d,assemtree b 
       where
          d.productid=b.productid 
    end
       go