MySQL

Usage

Alter table

Add a column to a table

We can add a column to a table with a specified order with the keyword FIRST to the front of all columns or AFTER `exist_column_name` to after the column `exist_column_name`.

ALTER TABLE `table_name` ADD COLUMN `new_column_name` VARCHAR ( 255 ) NOT NULL DEFAULT '' COMMENT 'some_comments' AFTER `exist_column_name`;

Change the data type of a column

ALTER TABLE `table_name` MODIFY COLUMN `exist_column_name` VARCHAR ( 255 ) NOT NULL DEFAULT '' COMMENT 'some_comments';

Last updated