Mysql--alter命令

來源:互聯網
上載者:User

標籤:

alter add命令用來增加表的欄位。

alter add命令格式:alter table 表名 add欄位 類型 其他;

例如,在表MyClass中添加了一個欄位passtest,類型為int(4),預設值為0:
   mysql> alter table MyClass add passtest int(4) default ‘0‘;

1) 加索引
   mysql> alter table 表名 add index 索引名 (欄位名1[,欄位名2 …]);

例子: mysql> alter table employee add index emp_name (name);

2) 加主關鍵字的索引
    mysql> alter table 表名 add primary key (欄位名);

例子: mysql> alter table employee add primary key(id);

3) 加唯一限制條件的索引
   mysql> alter table 表名 add unique 索引名 (欄位名);

例子: mysql> alter table employee add unique emp_name2(cardnumber);

4) 刪除某個索引
   mysql> alter table 表名 drop index 索引名;

例子: mysql>alter table employee drop index emp_name;

5) 增加欄位
    mysql> ALTER TABLE table_name ADD field_name field_type;

6) 修改原欄位名稱及類型
    mysql> ALTER TABLE table_name CHANGE old_field_name new_field_name field_type;

7) 刪除欄位
    MySQL ALTER TABLE table_name DROP field_name;

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.