明辉站/应用软件/内容

mysql索引index相关命令的详细介绍

应用软件2023-07-17 阅读
[摘要]本文主要内容:显示表中多有的索引show all index添加索引ADD INDEX, 添加唯一索引add unique index多列联合添加索引,primary key关键词index vs keyshow all indexshow index from tb_name 例如:show ...

本文主要内容:

  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;

这里写图片描述


添加索引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中文网其它相关文章!


学习教程快速掌握从入门到精通的SQL知识。

……

相关阅读