sql触发器无法正常工作帮帮我

时间:2011-08-02 05:54:17

标签: mysql

delimiter $$
drop TRIGGER if EXISTS upflttyprateTrig
create TRIGGER upflttyprateTrig

AFTER UPDATE ON flttyprate
FOR EACH ROW BEGIN

INSERT INTO `histflttyprate` (
               `flttyprate_Id`, 
               `flttyprate_Flttyp_Id_Fk`, 
               `flttyprate_Date_Eff`, 
               `flttyprate_Date_Ineff`, 
               `flttyprate_IFR`, 
               `flttyprate_Single`, 
               `flttyprate_Multi`, 
               `flttyprate_Rate_Per_Hr`, 
               `flttyprate_Night_Surchage`, 
               `flttyprate_Status`, 
               `flttyprate_Token`) 
VALUES (        
                NEW.flttyprate_Id,
                NEW.flttyprate_Flttyp_Id_Fk, 
                NEW.flttyprate_Date_Eff, 
                NEW.flttyprate_Date_Ineff, 
                NEW.flttyprate_IFR, 
                NEW.flttyprate_Single, 
                NEW.flttyprate_Multi, 
                NEW.flttyprate_Rate_Per_Hr, 
                NEW.flttyprate_Night_Surchage, 
                NEW.flttyprate_Status, 
                NEW.flttyprate_Token);

END$$

不起作用为什么实际的语法是mysqlversion 5.0

1 个答案:

答案 0 :(得分:0)

DROP TRIGGER语句中不支持“IF EXISTS”子句。 并在'DROP TRIGGER ...'语句后添加分隔符。


修改information_schematriggers表中读取有关触发器存在的信息;然后放下触发器。在应用程序中执行此操作或编写存储过程。

示例:

DELIMITER $$

CREATE PROCEDURE drop_trigger()
BEGIN
  SET @exist = NULL;

  SELECT 1
  INTO
    @exist
  FROM
    information_schema.triggers
  WHERE
    trigger_schema = 'test'
    AND trigger_name = 'trigger1';

  IF @exist IS NOT NULL THEN
    DROP TRIGGER test.trigger1;
  END IF;

END
$$

DELIMITER ;