Home > Database > Mysql Tutorial > body text

Detailed introduction to mysql index index related commands

黄舟
Release: 2017-09-26 11:18:00
Original
1802 people have browsed it

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;
Copy after login

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`)
Copy after login

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` )
Copy after login

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
Copy after login
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) 
...
Copy after login
There’s no difference. They are synonyms.This was implemented for 
 compatibility with other database systems.
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template