Home  >  Article  >  Database  >  Detailed introduction to mysql index index related commands

Detailed introduction to mysql index index related commands

黄舟
黄舟Original
2017-09-26 11:18:001786browse

Main content of this article:

  1. Show all indexes in the tableshow all index

  2. Add index ADD INDEX, add Unique index add unique index

  3. Multiple columns jointly add index, primary key

  4. Keyword index vs key


show all index

show index from tb_name For example:

show index from springdemo.blog;

Detailed introduction to mysql index index related commands


Add index ADD INDEX, add unique 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`)

Multi-column joint index, add primary key

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

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

Keyword index vs key

When creating the table time, there is no difference between these two keywords, equivalent to synonyms

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.

The above is the detailed content of Detailed introduction to mysql index index related commands. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn