我试图同时将信息添加到两个表中。一张桌子

时间:2014-10-30 17:17:11

标签: mysql sql-insert mysql-error-1064

尝试填充表

时出错

我想将数据输入到表中的单个行中,第一组数据是从表单输入生成的,第二组是从另一个表中自动递增。

INSERT INTO Bar_Location2 (`Bar_Admitted`) VALUES ("{57}");<br>
INSERT INTO Bar_Location2 (Your_ID) SELECT Your_ID FROM Your_Detail;

我可以单独执行每个查询,并且表格将填充(不幸的是在不同的行上),但是当我将两者合并时,我得到以下错误:

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 'INSERT INTO Bar_Location2 (Your_ID) SELECT Your_ID FROM Your_Detail' at line 2 SQL=INSERT INTO Bar_Location2 (`Bar_Admitted`) VALUES ("{57}"); INSERT INTO Bar_Location2 (Your_ID) SELECT Your_ID FROM Your_Detail;

我也尝试过:

START TRANSACTION;<br>
INSERT INTO Bar_Location2 (`Bar_Admitted`) VALUES ("{57}");<br> 
INSERT INTO Bar_Location2 (Your_ID) SELECT Your_ID FROM Your_Detail;<br>
COMMIT;

并再次收到相同的错误消息。

1 个答案:

答案 0 :(得分:0)

尝试没有大括号

INSERT INTO Bar_Location2 (Bar_Admitted) VALUES ("57");

以这种形式的查询

 START TRANSACTION
 INSERT INTO Bar_Location2 (`Bar_Admitted`) VALUES ("57");
 INSERT INTO Bar_Location2 (Your_ID) SELECT Your_Detail.Your_ID FROM Your_Detail;
 COMMIT;
 END OF TRANSACTION