i'm trying to alter a table's column name but i keep getting an error.

alter table GelderlandDist change inauguration 'inauguration date';

but i keep getting an error:

ERROR 1064 (42000): 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 ''inau
guration date'' at line 1

My problem is I'm trying to include a space in the column name and I know I can do it because my third column is called "country code" with a space in between, but I'm not sure how to alter the table to change it

Recommended Answers

Backticks, as JorgeM said, not single or double quotes.

alter table GelderlandDist change inauguration `inauguration date` DATE

You need to specify the type as well. From the manual: "You can rename a column …

Jump to Post

You are still using single quotes. Try back ticks instead. There are not the same character.

Jump to Post

All 5 Replies

Try using back ticks around the field name that has a space.

I tried that, I just ended up deleting the table and recreating it with no spaces. If you know another way that'd be great, i tried using (') and (").

Backticks, as JorgeM said, not single or double quotes.

alter table GelderlandDist change inauguration `inauguration date` DATE

You need to specify the type as well. From the manual: "You can rename a column using a CHANGE old_col_name new_col_name column_definition clause. To do so, specify the old and new column names and the definition that the column currently has."

mysql> alter table GelderlandDist change inauguration 'inauguration date' DATE;
ERROR 1064 (42000): 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 ''inau
guration date' DATE' at line 1

Any idea where I went wrong? I'm in the using the world database, I don't know if that detail is important.

You are still using single quotes. Try back ticks instead. There are not the same character.

commented: Dude thank you so much worked like a charm. Your the man +1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.