mysql中三种修改列的方式

来源:互联网 发布:淘宝怎么设置店铺简介 编辑:程序博客网 时间:2024/05/06 15:29

mysql中有三种修改列的语句

ALTER [COLUMN] col_name {SET DEFAULT literal | DROP DEFAULT}

CHANGE [COLUMN] old_col_name new_col_name column_definition

MODIFY [COLUMN] col_name column_definition

他们的区别
CHANGE:

Can rename a column and change its definition, or both.

Has more capability than MODIFY, but at the expense of convenience for some operations. CHANGE requires naming the column twice if not renaming it.

With FIRST or AFTER, can reorder columns.

MODIFY:

Can change a column definition but not its name.

More convenient than CHANGE to change a column definition without renaming it.

With FIRST or AFTER, can reorder columns.

ALTER: Used only to change a column default value.