删除数据库表中的列
在数据库表中删除指定的列,可使用以下命令:
alter table table_name drop col_name;
增加数据库表中的单列
在数据库表中添加新的单列,可使用以下命令:
alter table table_name add col_name col_type comment 'xxx';
增加数据库表中的多列
在数据库表中添加多个新列,可使用以下命令:
alter table table_name add col_name col_type comment 'xxx', add col_name col_type(col_length) comment 'xxx';
在表中增加字段并指定其位置
在数据库表中添加新字段并指定其位置(如表头或表尾)可使用以下命令:
- 将新字段添加到表头:
alter table table_name add col_name col_type COMMENT 'sss' FIRST;
- 将新字段添加到表尾:
alter table table_name add col_name col_type COMMENT 'sss' AFTER col_name_1;
使用MODIFY命令修改字段类型
修改字段的类型可使用以下命令:
alter table table_name modify column col_name col_type;
使用CHANGE命令修改字段类型
修改字段名称及其类型可使用以下命令:
alter table table_name change col_name new_col_name new_col_type;