我的触发器语句出错

时间:2012-09-19 03:08:59

标签: mysql sql triggers

请帮我在触发器声明中找到错误。

CREATE TRIGGER textmain_insert BEFORE INSERT ON textmain
FOR EACH ROW 
BEGIN
    IF NEW.text_create_datetime = '0000-00-00 00:00:00' THEN
        SET NEW.text_create_datetime = NOW();
    END IF
    IF NEW.text_update_datetime = '0000-00-00 00:00:00' THEN
        SET NEW.text_update_datetime = NOW();
    END IF
END;

1 个答案:

答案 0 :(得分:1)

  • 更改delimiter
  • 在每个end if
  • 之后终止

试,

DELIMITER $$
CREATE TRIGGER textmain_insert BEFORE INSERT ON textmain
FOR EACH ROW 
BEGIN
    IF NEW.text_create_datetime = '0000-00-00 00:00:00' THEN
        SET NEW.text_create_datetime = NOW();
    END IF;
    IF NEW.text_update_datetime = '0000-00-00 00:00:00' THEN
        SET NEW.text_update_datetime = NOW();
    END IF;
END $$
DELIMITER ;