《mysql索引操作》要點(diǎn):
本文介紹了mysql索引操作,希望對(duì)您有用。如果有疑問(wèn),可以聯(lián)系我們。
歡迎提錯(cuò),歡迎交流!
索引是對(duì)數(shù)據(jù)庫(kù)里加了索引的數(shù)據(jù)預(yù)先進(jìn)行排序,就像書(shū)的目錄,可以?xún)?yōu)化查詢(xún)速度,但是會(huì)降低增刪改速度,占用磁盤(pán)空間.
根據(jù)索引的數(shù)據(jù)結(jié)構(gòu)分為hash索引和b-tree索引.
增加主鍵索引
alter table tab_name add primary key (column_list);
增加唯一索引
alter table tab_name add unique (column_list);
增加普通索引
alter table tab_name add index index_name(column_list);
增加聯(lián)合索引
alter table tab_name add index index_name (column,column,...);
alter table tab_name drop index index_name;
alter table tab_name drop primary key;
*刪除主鍵索引要先修改掉auto_increment字段
*索引不能修改,只能刪除后重新添加
show index from tab_name;
例子:
mysql> alter table user add index type(type);
Query OK, 0 rows affected (0.19 sec)
可見(jiàn)user表有兩個(gè)索引,一個(gè)主鍵,一個(gè)type索引
歡迎參與《mysql索引操作》討論,分享您的想法,維易PHP學(xué)院為您提供專(zhuān)業(yè)教程。
轉(zhuǎn)載請(qǐng)注明本頁(yè)網(wǎng)址:
http://www.snjht.com/jiaocheng/7666.html