语法错误:创建MySQL触发器时​​“缺少分号”

时间:2016-02-21 10:09:52

标签: mysql triggers

我的触发查询:

CREATE DEFINER = CURRENT_USER TRIGGER `test`.`users_AFTER_INSERT` AFTER INSERT ON `users` FOR EACH ROW
BEGIN
 UPDATE test.users
 SET enabled=1
    FROM Inserted i
    WHERE username = i.username
END

它抱怨这部分:SET enabled=1。我试过添加引号,没有帮助。

很可能语法错了,但我无法弄清楚这里到底出了什么问题。

编辑:

或者可以这样做吗?

CREATE DEFINER = CURRENT_USER TRIGGER `test`.`users_AFTER_INSERT` AFTER INSERT ON `users` FOR EACH ROW
BEGIN
 UPDATE test.users
 SET enabled=1
 WHERE username = NEW.username;
END

1 个答案:

答案 0 :(得分:1)

删除from inserted查询:

delimiter | 
CREATE DEFINER = CURRENT_USER TRIGGER `test`.`users_AFTER_INSERT` AFTER INSERT ON `users` FOR EACH ROW
BEGIN
 UPDATE test.users
 SET enabled=1
    WHERE username = i.username;
END
| 
delimiter ;