我想将表复制到两个不同的表中
为此,我写了以下程序。
我想要连接temp1表的fname和lname,并希望用字符串值' Person'来放入另一个表atom。
在table atom插入值后,我想插入id并使用此插入的id(g_id
)将数据插入新表用户。
DELIMITER //
CREATE PROCEDURE cpy()
BEGIN
insert into atom values(name,type) select concat(temp1.fname,temp.lname), 'Person' from temp1;
SET g_id= LAST_INSERT_ID();
insert into user(id,mobno,password,fname,lname,mailid,dob,gender)
select g_id,mobno,password,fname,lname,mailid,dob,gender from temp1;
END //
DELIMITER ;
此代码无法正常运行错误
ERROR 1064 (42000): 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 'selec
t temp1.fname, 'Person' from temp1;
SET g_id= LAST_INSERT_ID();
insert int' at line 3
答案 0 :(得分:0)
尝试:
DELIMITER //
CREATE PROCEDURE cpy()
BEGIN
DECLARE g_id INT;
insert into atom /*values*/ (name,type)
select concat(temp1.fname,temp.lname), 'Person' from temp1;
SET g_id = LAST_INSERT_ID();
insert into user (id,mobno,password,fname,lname,mailid,dob,gender)
select g_id,mobno,password,fname,lname,mailid,dob,gender from temp1;
END//
DELIMITER ;