MySQL triggers cannot update rows in same table the trigger is assigned to. Suggested workaround?

前端 未结 5 1879
鱼传尺愫
鱼传尺愫 2020-11-28 15:11

MySQL doesn\'t currently support updating rows in the same table the trigger is assigned to since the call could become recursive. Does anyone have suggestions on a good wor

5条回答
  •  离开以前
    2020-11-28 16:13

    You can actually do that The below is an example for same

    DELIMITER $$
    create trigger test2 
    before insert on ptrt 
    for each row 
    begin 
    if NEW.DType = "A" then 
    set NEW.PA = 500; 
    
    elseif NEW.DType = "B" then 
    set NEW.PA = 1000; 
    
    else 
    set NEW.PA = 0; 
    END IF; 
    END;$$
    
    DELIMITER;
    

提交回复
热议问题