[英]MySQL + JAVA - Can't insert a table into another
I can't seem to insert my old table into the new table. 我似乎无法将旧表插入新表。 Very weird
很奇怪
Code: 码:
INSERT INTO 'newhawk_playewadwds' (`player_id`,'player') SELECT `player_id`,'player' FROM 'hawk_playewadwds';
Error: 错误:
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
Extra info: 额外信息:
Both tables exist and have slightly diffrent column structors (One has a varchar(50), while the other doesn't). 这两个表都存在并且具有略有不同的列结构(一个具有varchar(50),而另一个则没有)。 Which is why i included the direct columns in the statement.
这就是为什么我在语句中包括直接列的原因。
Quotes are delimiters for strings. 引号是字符串的定界符。 Use backticks to escape column and table names, not quotes.
使用反引号转义列和表名,而不是引号。
INSERT INTO `newhawk_playewadwds` (`player_id`,`player`)
SELECT `player_id`,`player`
FROM `hawk_playewadwds`;
But you actually only need to escape the reserved words . 但是实际上您只需要转义保留字即可 。
Try to replace '
char with table names and for column player
as below 尝试用表名和列
player
替换'
char,如下所示
INSERT INTO `newhawk_playewadwds` (`player_id`,`player`)
SELECT `player_id`,`player`
FROM `hawk_playewadwds`;
Use backticks across the query. 在查询中使用反引号。 You are using backticks and single quotes.
您正在使用反引号和单引号。 Either use backticks or remove the single quotes:
使用反引号或删除单引号:
-- 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;
Another thing, as you mentioned column structures are different, 另一件事,正如您提到的列结构不同,
newhawk_playewadwds
has column > 50, and hawk_playewadwds
has < 50, It shouldn't be a problem newhawk_playewadwds
列> 50,而hawk_playewadwds
列<50,则应该没问题 If hawk_playewadwds' has > 50 and
newhawk_playewadwds` has <50, then do either of the following: 如果
hawk_playewadwds' has > 50 and
<50,则执行以下任一操作:
newhawk_playewadwds
to same size of hawk_playewadwds
newhawk_playewadwds
大小hawk_playewadwds
大小 Use Substring in select as: 在选择中使用Substring作为:
INSERT INTO `newhawk_playewadwds` (`player_id`,`player`) SELECT `player_id`,SUBSTRING(`player` ,1,50) FROM `hawk_playewadwds`;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.