我建議觸發:MySQL的觸發器定義 - 1064錯誤
#START TRIGGER
delimiter //
DECLARE msg VARCHAR(255);
CREATE TRIGGER passStandard_check BEFORE INSERT ON Module
FOR EACH ROW
BEGIN
IF NEW.passStandard < 0 || NEW.passStandard > 1 THEN
set msg = concat('Trigger Error: Pass Standard: ', cast(NEW.passStandard as char));
signal sqlstate '45000' set message_text = msg;
END
//
delimiter ;
#END TRIGGER
,但我得到了以下錯誤:
Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DECLARE msg VARCHAR(255); CREATE TRIGGER passStandard_check BEFORE INSERT ON Mod' at line 1
添加在END IF
沒有任何區別。
passStandard
設置爲INT NOT NULL
。
編輯
我以後移動DECLARE
聲明BEGIN
:
#START TRIGGER
delimiter //
CREATE TRIGGER passStandard_check BEFORE INSERT ON Module
FOR EACH ROW
BEGIN
DECLARE msg VARCHAR(255);
IF NEW.passStandard < 0 || NEW.passStandard > 1 THEN
set msg = concat('Trigger Error: Pass Standard: ', cast(NEW.passStandard as char));
signal sqlstate '45000' set message_text = msg;
END IF;
END
//
delimiter ;
#END TRIGGER
但我仍然得到這個錯誤:
Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'sqlstate '45000' set message_text = msg; END IF; END' at line 7
不,不是這樣。 (另請參閱@clime的答案) – 2012-01-28 01:48:28
「END IF」後面的分號錯過 – 2012-01-28 01:54:44
不用哈哈。我已經添加了分號並更新了錯誤(雖然同樣的錯誤) – 2012-01-28 01:58:55