【實習記】2014-09-02MySQL資料庫中key與index區別

來源:互聯網
上載者:User

標籤:style   blog   http   os   io   使用   ar   資料   2014   

  

做資料庫最佳化時,使用sql語句調整資料庫,在此記錄一下。

好部落格,好文章

《mysql常用SQL語句》
http://www.cnblogs.com/jevo/p/3257222.html

《MySQL 主鍵與索引的聯絡與區別分析》
http://www.jb51.net/article/34037.htm

1. 主鍵一定是唯一性索引,唯一性索引並不一定就是主鍵。

2. 一個表中可以有多個唯一性索引,但只能有一個主鍵。

3. 主鍵列不允許空值,而唯一性索引列允許空值。

4. 索引可以提高查詢的速度。

在MySQL中,INDEX和KEY的概念是一樣的。
Key即索引值,是關聯式模式理論中的一部份,用於資料完整性檢否與唯一性限制式等。而Index則處於實現層面,比如可以對錶個的任意列建立索引



修改資料庫表結構的語句:廢除原主鍵,建新主鍵,刪除首碼行。

lock tables t_IP0040T1 write;alter table t_IP0040T1 drop primary key;alter table t_IP0040T1 drop column Fissuer_acc_range_prefix;# primary need notalter table t_IP0040T1 add Fid bigint primary key auto_increment;alter table t_IP0040T1 add unique key (Fissuer_acc_range_low, Fgcms_product_id);unlock tables;

 



記錄:

alter table t_IP0040T1 add Fid bigint primary key auto_increment;   # 可以直接增加自增主鍵# 等於以下兩句,primary可省略是為了相容其他資料庫。alter table t_IP0040T1 add Fid bigint not null;                     # 此時都為0alter table t_IP0040T1 change Fid Fid bigint key auto_increment;    # 現在是1、2、3、4……# 如果 key 是 index ,則出錯。此處key不等於index。

 

 

【實習記】2014-09-02MySQL資料庫中key與index區別

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.