Change column name in MariaDB
Asked Answered
B

3

12

I have this column in this database with a spacebar included, which I want to change.

ALTER TABLE . CHANGE COLUMN `Anzahl Personen` AnzahlPersonen int(11); 

After using this line in the command line the output is as following:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'CHANGE COLUMN `Anzahl Personen` AnzahlPersonen int(11)' at line 1

Yeah, I have no Idea, what I am doing wrong.

Breaststroke answered 13/2, 2015 at 20:13 Comment(0)
L
19

If you are using dot (.) instead of table name that is why you have error. You have to specify table name:

ALTER TABLE `table_name` CHANGE COLUMN `Anzahl Personen` AnzahlPersonen int(11);
Locomobile answered 13/2, 2015 at 20:24 Comment(1)
ALTER TABLE table_name` CHANGE COLUMN Anzahl Personen AnzahlPersonen;` Does not work. The column datatype should be included even thought you don't plan to change it!Bearing
C
3

ALTER TABLE <table_name> CHANGE COLUMN old_name new_name column_definition

https://jira.mariadb.org/browse/MDEV-16290

Chromogenic answered 16/1, 2019 at 21:5 Comment(0)
O
-1

don't need to write single quotes on old column name

like: ALTER TABLE table_name CHANGE COLUMN Anzahl Personen AnzahlPersonen int(11);

Overripe answered 1/3, 2023 at 5:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.