有人知道我的sintaxys中有什麼錯誤嗎?在mysql中遇到觸發器問題
CREATE TRIGGUER safe_pass AFTER UPDATE ON usuario
FOR EACH ROW BEGIN
IF OLD.clave <> NEW.clave THEN
UPDATE usuario SET Clave = SHA1(MD5(NEW.clave)) WHERE id_usuario = NEW.id_usuario;
END IF;
END;
#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 'TRIGGUER safe_pass AFTER UPDATE ON usuario
FOR EACH ROW BEGIN
IF OLD.clave <' at line 1
我有使用SQL Server的經驗,但MySQL對我來說是頭痛的問題。 我擁有的MySQL版本是MySQL數據庫版本5.0.51b。
感謝和問候
對不起,我爲我的錯誤真的很抱歉,我犯了無限建議我的變化。
錯誤SQL:
CREATE TRIGGER safe_pass AFTER UPDATE ON usuario
FOR EACH ROW BEGIN
IF OLD.clave <> NEW.clave THEN
UPDATE usuario SET Clave = SHA1(MD5(NEW.clave)) WHERE id_usuario = NEW.id_usuario
END IF;
END;
,其結果是:
#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 'END IF' at line 6
感謝Siride,我試試這個:
CREATE TRIGGER safe_pass AFTER UPDATE ON usuario
FOR EACH ROW BEGIN
IF OLD.clave <> NEW.clave THEN
UPDATE usuario SET Clave = SHA1(MD5(NEW.clave)) WHERE id_usuario = NEW.id_usuario;
END IF;
END;
,結果是:
#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 '' at line 5
我不得不從控制檯做到這一點,而最終的腳本是:
DELIMITER //
CREATE TRIGGER safe_pass BEFORE UPDATE ON usuario
FOR EACH ROW BEGIN
IF OLD.clave <> NEW.clave THEN
SET NEW.clave = SHA1(MD5(NEW.clave));
END IF;
END;//
DELIMITER ;
終於我解決了問題 –