Rename a table in MySQL
MysqlDatabaseTable RenameMysql Problem Overview
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
.
Mysql Solutions
Solution 1 - Mysql
group
is a keyword (part of http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html">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.
Solution 2 - Mysql
Please try
RENAME TABLE `oldTableName` TO `newTableName`
Solution 3 - Mysql
The MySQL syntax for RENAME TABLE
statement is the following:
RENAME TABLE <old_table_name> TO <new_table_name>
In your query, you've used group
which is one of the keywords in MySQL. Try to avoid MySQL keywords for names while creating tables, field names and so on.
Solution 4 - Mysql
ALTER TABLE old_table_name RENAME new_table_name;
or
RENAME TABLE old_table_name TO new_table_name;
Solution 5 - Mysql
Table name change
RENAME TABLE old_table_name TO new_table_name;
Solution 6 - Mysql
Rename a table in MySQL :
ALTER TABLE current_name RENAME new_name;
Solution 7 - Mysql
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`;
Solution 8 - Mysql
ALTER TABLE `group` RENAME `member`
group is keyword so you must have to enclose into group
Solution 9 - Mysql
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 `
Solution 10 - Mysql
RENAME TABLE tb1 TO tb2;
tb1 - current table name. tb2 - the name you want your table to be called.
Solution 11 - Mysql
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`;
Solution 12 - Mysql
Try any of these
RENAME TABLE `group` TO `member`;
or
ALTER TABLE `group` RENAME `member`;
Solution 13 - Mysql
> 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;
Solution 14 - Mysql
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.
Solution 15 - Mysql
You can use
RENAME TABLE `group` TO `member`;
Use back tick (`) instead of single quote (').
Solution 16 - Mysql
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;
Solution 17 - Mysql
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.