我试图在触发时插入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_Device
和LoginDatabase
表中。但是我遇到了语法错误。
非常感谢任何帮助。谢谢!
答案 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 ;