mysql alter 用法,修改表,字段等信息

一: 修改表信息

1.修改表名 

alter table test_a rename to sys_app;

 2.修改表註釋   

alter table sys_application comment '系統信息表';

 

 

二:修改字段信息

1.修改字段類型和註釋

alter table sys_application  modify column app_name varchar(20) COMMENT '應用的名稱';

2.修改字段類型

alter table sys_application  modify column app_name text;

3.單獨修改字段註釋 

目前沒發現有單獨修改字段註釋的命令語句。

4.設置字段允許爲空

alter table sys_application  modify column description varchar(255) null COMMENT '應用描述';

 5.增加一個字段,設好數據類型,且不爲空,添加註釋

alert table sys_application add `url` varchar(255) not null comment '應用訪問地址';  

 6.增加主鍵 

alter table t_app add aid int(5) not null ,add primary key (aid);  

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.在某個字段後增加字段

alter table `t_app` add column gateway_id int  not null default 0 AFTER `aid`; #(在哪個字段後面添加)  

12.調整字段順序 

alter table t_app  change gateway_id gateway_id int not null after aid ; #(注意gateway_id出現了2次)

 

發佈了371 篇原創文章 · 獲贊 1033 · 訪問量 173萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章