標籤: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區別