0

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

3
Contributors
5
Replies
32
Views
4 Years
Discussion Span
Last Post by JorgeM
1

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

Edited by JorgeM

0

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 (").

1

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."

Edited by pritaeas

0
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.

2

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

Votes + Comments
Dude thank you so much worked like a charm. Your the man
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.