bill表中的actualmoney这列值是数值型的,只要这列值发生变化就让它自动变为0,这样的触发器完整写法是什么,请提供一下完整的写法,谢谢

解决方案 »

  1.   

    不好意思,我重新补充一下,bill表中有两列,分别是money和actualmoney,只要actualmoeny的值是money的2倍,就让actualmoney自动变为0
      

  2.   

    create trigger tri_tb_up on tb 
    for update
    as
    if update(actualmoney)
    update t set actualmoney=0 from inserted i ,tb t where i.id=t.id 
      

  3.   

    楼上的,条件怎么加呢,我是菜鸟,if update(actualmoney) and actualmoney=2*money 这样写告诉我不对,麻烦你再帮我一下吧
      

  4.   


    楼上的,条件怎么加呢,我是菜鸟,if update(actualmoney) and actualmoney=2*money 这样写告诉我不对,麻烦你再帮我一下吧
      

  5.   


    create trigger tri_tb_up on tb  
    for update
    as
    if update(actualmoney)
    update t set actualmoney=0 from inserted i ,tb t where i.id=t.id AND t.actualmoney = t.money * 2
      

  6.   

    CREATE TRIGGER tri_tb_up
    ON tb
    FOR UPDATE
    AS
      IF UPDATE(actualmoney)
      UPDATE t
      SET    actualmoney = 0
      FROM   inserted i,
             tb t
      WHERE  i.id = t.id
             AND t.actualmoney = t.money * 2
      

  7.   


    create trigger tr_bill 
    on bill after insert,update
    as
    begin
     update a
     set a.actualmoney=0
     from bill a
     inner join inserted b
     on a.[money]=b.[money] and a.actualmoney=b.actualmoney 
     where b.actualmoeny=b.[money]*2
    end
      

  8.   


    为什么不能写在if update(actualmoney)后面呢,首先判断该列是否被修改和是否是money的2倍,然后再变0
      

  9.   

    这个可以再where条件后面判定  满足条件就更新 不满足就不更新