Home > Database > Mysql Tutorial > Experience sharing about index operations in Mysql

Experience sharing about index operations in Mysql

黄舟
Release: 2017-07-31 17:35:31
Original
1582 people have browsed it

Indexes do not depend on storage space. If used properly, they can improve query efficiency.

This article will show the addition and deletion operations of indexes

1. Query on mysql Index information

Command:

 show index from staff;
Output:
mysql> show index from staff;
Empty set (0.00 sec)
Copy after login

Experience sharing about index operations in Mysql

2. Add a common index

Command:

create index idx_staff on staff(id);
Copy after login

Experience sharing about index operations in Mysql

3. Add UNIQUE index

Command:

create unique index idx_unique_staff on staff(id);
Copy after login

Tips:

You cannot use the CREATE INDEX statement to create a PRIMARY KEY index

Experience sharing about index operations in Mysql

4. Add the index through the alter command

Command:

alter table staff add index idx_staff_byAlter (id);
Copy after login

Experience sharing about index operations in Mysql

5. Delete index

Command 1:

 drop index idx_staff on staff;
Copy after login

Experience sharing about index operations in Mysql

6. Command 2 :

alter table staff drop index idx_staff_byAlter;
Copy after login

Experience sharing about index operations in Mysql

The above is the detailed content of Experience sharing about index operations in Mysql. 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