重命名 MySQL 中的表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12650370/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Rename a table in MySQL
提问by Anil Olakkal
Renaming a table is not working in MySQL
重命名表在 MySQL 中不起作用
RENAME TABLE group TO member;
The error message is
错误信息是
#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 'group
RENAME TO member' at line 1
The query is working fine on other tables for me, but not with the table group
.
查询对我来说在其他表上工作正常,但在 table 上却没有group
。
回答by Joachim Isaksson
group
is a keyword (part of GROUP BY) in MySQL, you need to surround it with backticks to show MySQL that you want it interpreted as a table name:
group
是MySQL 中的关键字(GROUP BY 的一部分),您需要用反引号将其括起来以向 MySQL 表明您希望将其解释为表名:
RENAME TABLE `group` TO `member`;
added(see comments)- Those are not single quotes.
添加(见评论)-那些不是单引号。
回答by Vijay Verma
Please try
请尝试
RENAME TABLE `oldTableName` TO `newTableName`
回答by phponwebsites
The mysql query for rename table is
重命名表的mysql查询是
Rename Table old_name TO new_name
In your query, you've used group which one of the keywords in MySQL. Try to avoid mysql keywords for name while creating table, field name and so on.
在您的查询中,您使用了 MySQL 中的哪个关键字之一。创建表、字段名等时尽量避免使用mysql关键字作为名称。
回答by Neeraj Kumar
ALTER TABLE old_table_name RENAME new_table_name;
or
或者
RENAME TABLE old_table_name TO new_table_name;
回答by Hasib Kamal
Rename a table in MySQL :
重命名 MySQL 中的表:
ALTER TABLE current_name RENAME new_name;
回答by A.A Noman
Table name change
表名更改
RENAME TABLE old_table_name TO new_table_name;
回答by Boris
group - is a reserved word in MySQL, that's why you see such error.
group - 是 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 'group
RENAME TO member' at line 1
You need to wrap table name into backticks:
您需要将表名包装成反引号:
RENAME TABLE `group` TO `member`;
回答by umar_
ALTER TABLE `group` RENAME `member`
group is keyword so you must have to enclose into group
group 是关键字,因此您必须包含在 group
回答by Koech
RENAME TABLE tb1 TO tb2;
tb1 - current table name. tb2 - the name you want your table to be called.
tb1 - 当前表名。tb2 - 您希望表的名称。
回答by user2426679
According to mysql docs: "to rename TEMPORARY
tables, RENAME TABLE
does not work. Use ALTER TABLE
instead."
根据mysql docs:“重命名TEMPORARY
表,RENAME TABLE
不起作用。ALTER TABLE
改用。”
So this is the most portable method:
所以这是最便携的方法:
ALTER TABLE `old_name` RENAME `new_name`;