我似乎无法将旧表插入新表中。非常奇怪
代码:
INSERT INTO 'newhawk_playewadwds' (`player_id`,'player') SELECT `player_id`,'player' FROM 'hawk_playewadwds';
错误:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You
have an error in your SQL syntax; check the manual that corresponds to your MySQ
L server version for the right syntax to use near ''newhawk_playewadwds' (`playe
r_id`,'player') SELECT `player_id`,'player' FROM 'h' at line 1
额外信息:
两个表都存在并且具有稍微不同的列结构(一个具有varchar(50),而另一个没有)。这就是我在声明中包含直接列的原因。
答案 0 :(得分:5)
引号是字符串的分隔符。使用反引号来转义列名和表名,而不是引号。
INSERT INTO `newhawk_playewadwds` (`player_id`,`player`)
SELECT `player_id`,`player`
FROM `hawk_playewadwds`;
但实际上你只需要逃避reserved words。
答案 1 :(得分:1)
尝试将'
字符替换为表名,将列player
替换为
INSERT INTO `newhawk_playewadwds` (`player_id`,`player`)
SELECT `player_id`,`player`
FROM `hawk_playewadwds`;
答案 2 :(得分:0)
在查询中使用反引号。您正在使用反引号和单引号。使用反引号或删除单引号:
-- This will work (Backticks only)
INSERT INTO `newhawk_playewadwds` (`player_id`,`player`)
SELECT `player_id`,`player`
FROM `hawk_playewadwds`;
-- This will also work (No backticks and no single quotes)
INSERT INTO newhawk_playewadwds (player_id,player)
SELECT player_id,player
FROM hawk_playewadwds;
另一件事,正如你提到的列结构不同,
newhawk_playewadwds
有列> 50,而hawk_playewadwds
已经< 50,这应该不是问题如果hawk_playewadwds' has > 50 and
newhawk_playewadwds`已经<50,请执行以下任一操作:
newhawk_playewadwds
的大小增加到hawk_playewadwds
在select as中使用Substring:
INSERT INTO `newhawk_playewadwds` (`player_id`,`player`)
SELECT `player_id`,SUBSTRING(`player` ,1,50)
FROM `hawk_playewadwds`;