Mysql 常见ALTER TABLE操作
刪除列
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 after col_name_1;
使用MODIFY修改字段類型
alter table table_name modify column col_name col_type;
使用CHANGE修改字段類型
alter table table_name change col_name col_name col_type;
使用CHANGE修改字段名稱
alter table table_name change old_col_name new_col_name col_type;
修改列類型、長度
alter table table_name change old_col_name new_col_name new_col_type;
?
查看表中列屬性
show columns from table_name;
修改表名
rename table old_table_name to new-table-name;
為字段設置NOT NULL和NULL
alter table table_name modify col_name col_type not null commit '字段注釋';
alter table table_name modify col_name col_type default null commit?'字段注釋';
修改字段的默認值
alter table table_name alter col_name set default 10000;
字段刪除默認值?
alter table table_name alter col_name drop default;
?
新增到指定位置語法
alter table app add `name` varchar(64) default '' commit '應用名稱' after `app_id`;
修改順序語法:alter table 表名 change 老字段名 新字段名 字段各種約束 after 字段;
alter table `app` change `title` `title` VARCHAR(64) default '' commit '名稱' after `name`;
總結
以上是生活随笔為你收集整理的Mysql 常见ALTER TABLE操作的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java对象生命周期
- 下一篇: python基础之序列类型的方法——列表