1. 增加列
1.1 增加的列位于最后文章源自运维生存时间-https://www.ttlsa.com/mysql/change-table-structure-sql/
alter table table_name add col_name varchar(20); alter table table_name add col_name varchar(20) default 'test' not null; alter table table_name add column col_name varchar(20) default 'test' not null;
1.2 增加的列在指定的列之后文章源自运维生存时间-https://www.ttlsa.com/mysql/change-table-structure-sql/
alter table table_name add col_name varchar(20) after exists_col_name;
1.3 增加的列位于第一列文章源自运维生存时间-https://www.ttlsa.com/mysql/change-table-structure-sql/
alter table table_name add col_name varchar(20) first;
2. 修改列文章源自运维生存时间-https://www.ttlsa.com/mysql/change-table-structure-sql/
2.1 修改列的类型文章源自运维生存时间-https://www.ttlsa.com/mysql/change-table-structure-sql/
alter table table_name modify col_name varchar(40); //假设原来的类型是varchar(20) alter table table_name modify col_name int(11); //从varchar修改为int alter table table_name change col_name col_name varchar(20); //从int修改为varchar
2.2 修改列名文章源自运维生存时间-https://www.ttlsa.com/mysql/change-table-structure-sql/
alter table table_name change old_col_name new_col_name varchar(20);
3. 删除列文章源自运维生存时间-https://www.ttlsa.com/mysql/change-table-structure-sql/
alter table table_name drop col_name; alter table table_name drop column col_name; 本文转自:http://www.netingcn.com/mysql-edit-table.html文章源自运维生存时间-https://www.ttlsa.com/mysql/change-table-structure-sql/文章源自运维生存时间-https://www.ttlsa.com/mysql/change-table-structure-sql/
我的微信
微信公众号
扫一扫关注运维生存时间公众号,获取最新技术文章~
评论