在触发器mysql中插入多个语句

时间:2014-11-20 07:34:15

标签: mysql triggers

我试图在触发时插入MYSQL中的多个表。我的代码如下:

CREATE TRIGGER createUsername AFTER INSERT ON UserDatabase
FOR EACH ROW BEGIN
INSERT INTO PushNotifications_Device (Username) VALUES (NEW.Username) 
INSERT INTO LoginDatabase (Username) VALUES (NEW.Username)
END

基本上,我们的想法是将新的Username(在进入UserDatabase之后)复制到PushNotifications_DeviceLoginDatabase表中。但是我遇到了语法错误。

非常感谢任何帮助。谢谢!

1 个答案:

答案 0 :(得分:0)

您缺少分隔符,触发器应为

delimiter //

CREATE TRIGGER createUsername AFTER INSERT ON UserDatabase
FOR EACH ROW 
BEGIN
  INSERT INTO PushNotifications_Device (Username) VALUES (NEW.Username) ;
  INSERT INTO LoginDatabase (Username) VALUES (NEW.Username);
END;//

delimiter ;