使用InnoDB在MySQL 5.5.9上运行。
我创建了以下触发器:
CREATE TRIGGER TRIGGER_Products_Insert
AFTER INSERT ON Products
FOR EACH ROW
BEGIN
UPDATE Products
SET current = 0
WHERE id = new.id
AND current = 1
AND autonumber <> new.autonumber
END;
MySQLWorkbench在最后一行显示语法错误,执行此操作会引发以下错误
错误代码:1064。您的SQL语法有错误;检查与MySQL服务器版本对应的手册,以便在第11行的“END”附近使用正确的语法
我的错误在哪里?
答案 0 :(得分:2)
http://dev.mysql.com/doc/refman/5.5/en/create-trigger.html
DELIMITER |
CREATE TRIGGER TRIGGER_Products_Insert AFTER INSERT ON Products
FOR EACH ROW BEGIN
UPDATE Products
SET current = 0
WHERE id = new.id
AND current = 1
AND autonumber <> new.autonumber;
END;
|
DELIMITER ;
答案 1 :(得分:0)
您在;
关键字前缺少END
:
CREATE TRIGGER TRIGGER_Products_Insert
AFTER INSERT ON Products
FOR EACH ROW
BEGIN
UPDATE Products
SET current = 0
WHERE id = new.id
AND current = 1
AND autonumber <> new.autonumber;
END;