首頁  >  文章  >  資料庫  >  mysql索引index相關指令的詳細介紹

mysql索引index相關指令的詳細介紹

黄舟
黄舟原創
2017-09-26 11:18:001734瀏覽

本文主要內容:

  1. 顯示表中多有的索引show all index

  2. 新增索引ADD INDEX, 新增唯一索引add unique index

  3. 多列聯合添加索引,primary key

  4. 關鍵字index vs key


show all index

show index from  tb_name 例如:

show index from springdemo.blog;

mysql索引index相關指令的詳細介紹


新增索引ADD INDEX, 新增唯一索引add unique index

ALTER TABLE `table` ADD INDEX `product_id` (`product_id`)

# 创建唯一索引alter table tb_name  add unique index  `unique_idsrc_caffeversion` (`id_src`, `caffe_version`)

多列聯合索引,新增主鍵

#多列索引ALTER TABLE `table` ADD INDEX `index_name` (`col1`,`col2`)

# add primary key 添加主键ALTER TABLE `table_name` ADD PRIMARY KEY ( `column` )

關鍵字index vs key

#在建立表的時候,這兩個關鍵字沒什麼差別,相當於同義詞

What are differences between Index v.s. Key in MySQL
CREATE TABLE tasks ( 
task_id INT UNSIGNED NOT NULL AUTO_INCREMENT, 
INDEX parent (parent_id), 
....# However I found a code using KEY instead of INDEX as following....KEY order_date (order_date) 
...
There’s no difference. They are synonyms.This was implemented for 
 compatibility with other database systems.

以上是mysql索引index相關指令的詳細介紹的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn