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.
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 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.
ALTER TABLE old_table_name RENAME new_table_name;
or
RENAME TABLE old_table_name TO new_table_name;
Table name change
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
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 `
RENAME TABLE tb1 TO tb2;
tb1 - current table name.
tb2 - the name you want your table to be called.
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`;
Try any of these
RENAME TABLE `group` TO `member`;
or
ALTER TABLE `group` RENAME `member`;
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;
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
You can use
RENAME TABLE `group` TO `member`;
Use back tick (`) instead of single quote (').
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.
I am currently trying to insert brackets into the column name of my table. However, that results in an error when I run my script.
The format of my table in my script previously reads:
cursor.execute("CREATE TABLE IF NOT EXISTS table (date date, voltage decimal (2,2))")
I then made changes to this part of the script to add brackets to my table column name. It now reads:
cursor.execute("CREATE TABLE IF NOT EXISTS table (date date, voltage(V) decimal (2,2))")
After adding the brackets i.e. (V), the script fails to run.
The error I get is:
SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '(V) decimal (2,2))' at line 1
How can I add brackets to the column name without obtaining an error?
If you want to use special characters in the name of a database, table, or column, put the name in backticks.
CREATE TABLE IF NOT EXISTS table (
date date,
`voltage(V)` decimal (2,2)
)
You'll also need to use the backticks in all queries that refer to the column, so it will probably annoy all your other programmers.
See When to use single quotes, double quotes, and backticks in MySQL for more information about quoting in MySQL.
I've imported a csv into MySQL. PHPMyAdmin helpfully created a table called TABLE 8 (with a space).
When I try to rename in SQL:
RENAME TABLE 8 to gender
I get the 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 '`TABLE 8` to `gender`' at line 1
I have tried back-ticks, quotes... seemingly everything...
I guess it's the space that's causing the problem but I'm out of ideas.
The syntax is wrong, you're missing the table keyword (and yes, note the `s to escape the table name containing a space):
RENAME TABLE `TABLE 8` TO gender
Alternatively, you could use the fuller syntax:
ALTER TABLE `TABLE 8` RENAME TO gender
Update Student Set First Name='adwd' Where StudentID=123;
ERROR 1064 (42000): You have an error in your SQL syntax;
This query is not working in mysql , because the column name in my table is space separated. if i do the query on another column which is not comma separated it will work.
However ,i want to keep the first name as is. I tried using [] and `` and "" and '' none of them have worked. Is this just impossible to do and i have to rename my column names ?
I hope some1 can provide a good solution
thx community :)
try this
Update Student Set `First Name`='adwd' Where StudentID=123;
If you are using MySQL, the correct syntax is:
Update Student
Set `First Name` = 'adwd'
Where StudentID = 123;
If this doesn't work, then something else is wrong with the query apart from the column name. Note that backticks are used for escaping the column name in MySQL.
I have table in MySQL with years as column names like 1960, 1961, 1962... etc. Records are being inserted successfully. When I try to update table with query
UPDATE table1 SET 1960=0.0 WHERE id = 'abc'
it gives:
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 '1960=0.0 WHERE id='abc' at line 1
Is it due to columns names as numbers or something else is wrong?
try this:
UPDATE table1 SET `1960`='0.0' WHERE id = 'abc'
... added backticks to column name and single quotes around value (not really required for the value, but I always do it)
escape your column name with backticks
UPDATE table1 SET `1960` = 0.0 WHERE id = 'abc'
That has to be done if your column name is a reserved keyword in MySQL or a number.
You'll have to escape your column names by using the backtick character. The following manual page is somewhat dense but informative
Try...
UPDATE table1 SET `1960`=0.0 WHERE id = 'abc'