Modify MySQL table column definition

We may have to modify the table column definition in MySQL database. The syntax is

ALTER table db.tbl
CHANGE OLD_COLUMN_NAME    NEW_COLUMN_NAME    xxx...xxx;

The segment xxx…xxx represents the column definition of the column.

Example.
If I have a column definition
BOOLEAN NOT NULL DEFAULT FALSE COMMENT ‘Abc’
and I like to change the comment text to ‘XYZ’.

I must put full column definition again rather than simply changing the comment parameter. No matter what column parameter you want to change, you have to type all parameter again!

The MySQL statement to do so is

ALTER table db.tbl
CHANGE OLD_COLUMN_NAME    NEW_COLUMN_NAME    BOOLEAN    NOT NULL    DEFAULT FALSE    COMMENT 'XYZ';

oliver

Leave a Reply

Your email address will not be published. Required fields are marked *


*