Rename a table in MySQL

纵饮孤独 提交于 2019-11-28 15:18:32
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:

RENAME TABLE `group` TO `member`;

added(see comments)- Those are not single quotes.

Please try

RENAME TABLE  `oldTableName` TO  `newTableName`

The mysql query for rename table is

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.

ALTER TABLE old_table_name RENAME new_table_name;

or

RENAME TABLE old_table_name TO new_table_name;

Rename a table in MySQL :

ALTER TABLE current_name RENAME new_name;

group - is a reserved word in MySQL, that's why you see such error.

#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`;
ALTER TABLE `group` RENAME `member`

group is keyword so you must have to enclose into group

Table name change

RENAME TABLE name_old_table TO name_new_table;
RENAME TABLE tb1 TO tb2;

tb1 - current table name. tb2 - the name you want your table to be called.

Try any of these

RENAME TABLE `group` TO `member`;

or

ALTER TABLE `group` RENAME `member`;

According to mysql docs: "to rename TEMPORARY tables, RENAME TABLE does not work. Use ALTER TABLE instead."

So this is the most portable method:

ALTER TABLE `old_name` RENAME `new_name`;

Running The Alter Command

1.Click the SQL tab at the top.

2.In the text box enter the following command: ALTER TABLE exampletable RENAME TO new_table_name;

3.Click the go button.

source : https://my.bluehost.com/hosting/help/2158

Without giving the database name the table is can't be renamed in my case, I followed the below command to rename the table.

RENAME TABLE current_db.tbl_name TO current_db.tbl_name;

Right Click on View > New Query

And Type: EXEC sp_rename 'Table', 'NewName'

Then Click on Run button at the top left corner of the page.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!