2012-09-19 46 views
2

請幫我找到我的觸發語句中的錯誤。錯誤在我的觸發聲明

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
  • 更改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 ;