Tech Hacks

How to Rename Column in Mysql

To Rename a Column in Mysql we need to use the ALTER query with CHANGE COLUMN statement. The standard version of this query is:

ALTER [ONLINE | OFFLINE] [IGNORE] TABLE tbl_name
CHANGE [COLUMN] old_col_name new_col_name column_definition
[FIRST|AFTER col_name]


For Example:

ALTER TABLE City CHANGE CityId cityId varchar(25) NOT NULL;

Note: You will need to mention every constraint of the original column as defaults are assumed otherwise.