MySQL建立索引的SQL語句

2021-10-02 01:27:28 字數 715 閱讀 9002

1. 主鍵索引:建立表時自動建立   

2. 唯一索引:create unique index unique_index_warn[索引名稱] on cas_alarm[表名] (warn_id[列名])     

3. 普通索引:create index index_saas_report_service_status[索引名稱] on saas_report_service_status[表名] (service_status[列名]);   

4. 組合索引:create index index_saas_report_service_type[索引名稱] on saas_report_service_status[表名] (service_type[列名],service_status[列名],sort_value[列名]);

組合索引遵循最左字首原則,即此sql語句建立了兩個索引:

(1) service_type[列名],service_status[列名],sort_value[列名]

(2) service_type[列名]

其中唯一索引、普通索引、組合索引都是非聚集索引,乙個表中可以有多個非聚集索引

5. 檢視索引:show index from biz_service_type_iaas[表名]

mysql索引語句 mysql建立索引語句格式

專案需要將某個表的某兩個字段新增唯一索引,保證這兩個欄位的值不能同時重複。alter table 表名 add unique index 索引名 欄位1,欄位2 當表中已經存在重複資料的時候,新增的時候就會報錯,這時候需要將資料去重。1 先查出來重複的資料 select from select 字段...

sql語句 建立 查詢 索引語句

建立code欄位的索引 名稱叫 ix couponsinfodn code use activitydb goif exists select from sysindexes where name ix couponsinfodn code 檢測是否已經存在ix test tname索引 drop ...

建立SQL索引,檢視SQL效能語句收集

sql中建立主鍵非聚集索引和聚集索引 code 排序 聚集索引 create clustered index inx entry stock bi onentry stock d entry stock bi 建立非聚集索引 create nonclustered index inx entry s...