mysql alter 用法,修改表,欄位等資訊

來源:互聯網
上載者:User

標籤:color   add   char   log   alt   用法   rip   name   test   

一: 修改表資訊

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次)

 

mysql alter 用法,修改表,欄位等資訊

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.