触发于 MySQL

Trigger on MySQL

我正在尝试使用 phpMyAdmin 在 MySQL 中创建一个触发器,但我遇到了错误,而且我无法检测到错误。主要思想是在插入新用户时在表 stuffconfig 中创建一行。

代码:

CREATE TRIGGER create_stuff_and_config 
AFTER INSERT ON user
  FOR EACH ROW
BEGIN
    insert into stuff(user_id) values (NEW.user_id);     
    insert into config(user_id) values(NEW.user_id);
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

我已经检查了 MySQL 文档,但我发现我做得很好...

我也试过了:INSERT INTO stuff SET user_id = NEW.user_id;

谢谢!

好的,解决方法是添加分隔符...

DELIMITER //
CREATE TRIGGER create_stuff_and_config 
AFTER INSERT ON user
  FOR EACH ROW
BEGIN
    insert into stuff(user_id) values (NEW.user_id);     
    insert into config(user_id) values(NEW.user_id);
END; //
DELIMITER ;