码:

CREATE TRIGGER Table BEFORE INSERT ON Users
  FOR EACH ROW BEGIN
    INSERT INTO Table1 SET UserIdn = NEW.UserIdn;
    INSERT INTO Table2 SET UserIdn = NEW.UserIdn;
    INSERT INTO Table3 SET UserIdn = NEW.UserIdn;
    INSERT INTO Table4 SET UserIdn = NEW.UserIdn;
  END;


我们得到错误:

Error
SQL Query:


CREATE TRIGGER Table  BEFORE INSERT ON `Users`
  FOR EACH ROW BEGIN
    INSERT INTO Table1 SET UserIdn = NEW.UserIdn;
Answer MySQL:

#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 3


请告诉我哪里出错了,怎么办才对?

最佳答案

您的插入语法错误-您似乎混合了insertupdate

INSERT INTO Table1(UserIdn) VALUES(NEW.UserIdn);
...


(或者,如果您想更新现有行,请UPDATE Table1 SET UserIDn = NEW.UserIDn WHERE ...

SqlFiddle here

关于mysql - 添加触发器时出现Mysql错误-怎么回事?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23292504/

10-11 05:14