314
votes

Renaming a table is not working in 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.

17
Both sqls are the same. Try this rename table 'group' to member - user1406062
This illustrates nicely how pointless it is to use all-caps for keywords. - Martin Jambon
No, it does not. All-caps keywords improve readability and are expected standard style. - fmalina

17 Answers

515
votes

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.

143
votes

Please try

RENAME TABLE  `oldTableName` TO  `newTableName`
33
votes

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.

25
votes
ALTER TABLE old_table_name RENAME new_table_name;

or

RENAME TABLE old_table_name TO new_table_name;
23
votes

Table name change

RENAME TABLE old_table_name TO new_table_name;
19
votes

Rename a table in MySQL :

ALTER TABLE current_name RENAME new_name;
14
votes

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

group is keyword so you must have to enclose into group

9
votes
RENAME TABLE tb1 TO tb2;

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

9
votes

For Mysql 5.6.18 use the following command

ALTER TABLE `old_table` RENAME TO `new_table`

Also if there is an error saying ".... near RENAME TO ..." try removing the tick `

8
votes

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`;
6
votes

Try any of these

RENAME TABLE `group` TO `member`;

or

ALTER TABLE `group` RENAME `member`;
2
votes

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

2
votes

You can use

RENAME TABLE `group` TO `member`;

Use back tick (`) instead of single quote (').

2
votes

Rename table
Syntax The syntax to rename a table in MySQL is:

ALTER TABLE table_name
RENAME TO new_table_name;

Example
Let's look at an example that shows how to rename a table in MySQL using the ALTER TABLE statement.
or example:

ALTER TABLE contacts
RENAME TO people;
-1
votes

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;
-6
votes

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.