明輝手游網(wǎng)中心:是一個免費提供流行視頻軟件教程、在線學習分享的學習平臺!

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

[摘要]本文主要內容:顯示表中多有的索引show all index添加索引ADD INDEX, 添加唯一索引add unique index多列聯(lián)合添加索引,primary key關鍵詞index vs ...

本文主要內容:

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

  2. 添加索引ADD INDEX, 添加唯一索引add unique index

  3. 多列聯(lián)合添加索引,primary key

  4. 關鍵詞index vs key


show all index

show index from tb_name 例如:

show index from springdemo.blog;

這里寫圖片描述


添加索引ADD INDEX, 添加唯一索引add unique index

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

# 創(chuàng)建唯一索引alter table tb_name  add unique index  `unique_idsrc_caffeversion` (`id_src`, `caffe_version`)

多列聯(lián)合索引,添加主鍵

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

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

關鍵詞index vs key

在創(chuàng)建表的時候,這兩個關鍵詞沒什么區(qū)別,相當于同義詞

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中文網(wǎng)其它相關文章!


學習教程快速掌握從入門到精通的SQL知識。