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

Experience sharing about index operations in Mysql

黄舟
黄舟Original
2017-07-31 17:35:311531browse

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)

Experience sharing about index operations in Mysql

2. Add a common index

Command:

create index idx_staff on staff(id);

Experience sharing about index operations in Mysql

3. Add UNIQUE index

Command:

create unique index idx_unique_staff on staff(id);

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);

Experience sharing about index operations in Mysql

5. Delete index

Command 1:

 drop index idx_staff on staff;

Experience sharing about index operations in Mysql

6. Command 2 :

alter table staff drop index idx_staff_byAlter;

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!

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