ALTER语句
一: 修改表信息
1.修改表名
alter table test_a rename to sys_app;
2.修改表注釋
alter table sys_application
comment ‘系統(tǒng)信息表’;
二:修改字段信息
1.修改字段類型和注釋
alter table
sys_application modify column app_name varchar(20) COMMENT ‘應(yīng)用的名稱’;
2.修改字段類型
alter table sys_application modify column app_name text;
3.單獨(dú)修改字段注釋
目前沒(méi)發(fā)現(xiàn)有單獨(dú)修改字段注釋的命令語(yǔ)句。
4.設(shè)置字段允許為空
alter table
sys_application modify column description varchar(255) null COMMENT ‘應(yīng)用描述’;
5.增加一個(gè)字段,設(shè)好數(shù)據(jù)類型,且不為空,添加注釋
alert table sys_application add url varchar(255) not null comment ‘應(yīng)用訪問(wèn)地址’;
6.增刪加主鍵
alter table t_app add aid int(5) not null ,add primary key (aid);
alter table table_name drop primary key;
7.增加自增主鍵
alter table t_app add aid int(5) not null auto_increment ,add primary key (aid);
8.修改為自增主鍵
alter table t_app modify column aid int(5) auto_increment ;
9.修改字段名字(要重新指定該字段的類型)
alter table t_app change name
app_name varchar(20) not null;
10.刪除字段
alter table t_app drop aid;
11.在某個(gè)字段后增加字段
alter table t_app add column gateway_id int not null default 0 AFTER aid; #(在哪個(gè)字段后面添加)
12.調(diào)整字段順序
alter table t_app change gateway_id gateway_id int not null after aid ; #(注意gateway_id出現(xiàn)了2次)
總結(jié)
- 上一篇: 代码的坏味道之一——译自《重构》
- 下一篇: 【 Grey Hack 】万金油脚本:在