patternsqlCritical
ALTER TABLE - Rename a column
Viewed 0 times
altercolumntablerename
Problem
This is driving me nuts!
I want to rename a column from read-more to read_more in my blog table
I tried all this:
And I always get this!
I'm using MySQL 5.5
I want to rename a column from read-more to read_more in my blog table
I tried all this:
ALTER TABLE blog RENAME COLUMN read-more to read_more;
ALTER TABLE blog CHANGE COLUMN 'read-more' 'read_more' VARCHAR(255) NOT NULL;And I always get this!
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 'COLUMN read-more to read_more' at line 1I'm using MySQL 5.5
Solution
The valid syntax is close to your second try, but you need to escape the column names with backticks not with single quotes:
ALTER TABLE `blog` CHANGE COLUMN `read-more` `read_more` VARCHAR(255) NOT NULL;Code Snippets
ALTER TABLE `blog` CHANGE COLUMN `read-more` `read_more` VARCHAR(255) NOT NULL;Context
StackExchange Database Administrators Q#62051, answer score: 149
Revisions (0)
No revisions yet.