Mysql三个TRIGGERs单触发

时间:2013-09-03 07:15:44

标签: mysql triggers

我的Mysql表不支持创建多个触发器。但我有3个触发器用于三个更新查询,我如何使用单个触发器运行这些触发器,

  

错误:#1235 - 此版本的MySQL尚不支持'multiple   触发一个表'

具有相同的操作时间和事件

感谢

 CREATE TRIGGER `update_yeild2` BEFORE UPDATE ON `today_plan`
 FOR EACH ROW SET NEW.yeild = COALESCE((SELECT kiln_master.yeild 
                   FROM kiln_master
                   WHERE NEW.itemno = kiln_master.item  
                   AND  NEW.pattern = kiln_master.pattern
                   LIMIT 1), 0)


CREATE TRIGGER `update_yeild1` BEFORE UPDATE ON `today_plan`
 FOR EACH ROW SET NEW.temp = COALESCE((SELECT kiln_master.temp 
                   FROM kiln_master
                   WHERE NEW.itemno = kiln_master.item  
                   AND  NEW.pattern = kiln_master.pattern
                   LIMIT 1), 0)

CREATE TRIGGER `update_yeild0` BEFORE UPDATE ON `today_plan`
 FOR EACH ROW SET NEW.kiln = COALESCE((SELECT kiln_master.kiln 
                   FROM kiln_master
                   WHERE NEW.itemno = kiln_master.item  
                   AND  NEW.pattern = kiln_master.pattern
                   LIMIT 1), 0)

更新后的代码:

CREATE TRIGGER `update_yeild2` BEFORE UPDATE ON `today_plan`
 FOR EACH ROW 

BEGIN

SET NEW.yeild = COALESCE((SELECT kiln_master.yeild 
                   FROM kiln_master
                   WHERE NEW.itemno = kiln_master.item  
                   AND  NEW.pattern = kiln_master.pattern
                   LIMIT 1), 0);


  SET NEW.temp = COALESCE((SELECT kiln_master.temp 
                   FROM kiln_master
                   WHERE NEW.itemno = kiln_master.item  
                   AND  NEW.pattern = kiln_master.pattern
                   LIMIT 1), 0);

  SET NEW.kiln = COALESCE((SELECT kiln_master.kiln 
                   FROM kiln_master
                   WHERE NEW.itemno = kiln_master.item  
                   AND  NEW.pattern = kiln_master.pattern
                   LIMIT 1), 0);

END

感谢

工作代码:感谢RandomSeed

delimiter //

CREATE TRIGGER `update_yeild2` BEFORE UPDATE ON `today_plan`
 FOR EACH ROW 

BEGIN

SET NEW.yeild = COALESCE((SELECT kiln_master.yeild 
                   FROM kiln_master
                   WHERE NEW.itemno = kiln_master.item  
                   AND  NEW.pattern = kiln_master.pattern
                   LIMIT 1), 0);


  SET NEW.temp = COALESCE((SELECT kiln_master.temp 
                   FROM kiln_master
                   WHERE NEW.itemno = kiln_master.item  
                   AND  NEW.pattern = kiln_master.pattern
                   LIMIT 1), 0);

  SET NEW.kiln = COALESCE((SELECT kiln_master.kiln 
                   FROM kiln_master
                   WHERE NEW.itemno = kiln_master.item  
                   AND  NEW.pattern = kiln_master.pattern
                   LIMIT 1), 0);

END

//
delimiter ;

1 个答案:

答案 0 :(得分:1)

只需在一个触发器中包含三个触发器操作:

CREATE TRIGGER (...)
FOR EACH ROW
BEGIN
    SET NEW.yeild = (...) ;
    SET NEW.temp = (...) ;
    SET NEW.kiln = (...) ;
END ;