Home > Database > Mysql Tutorial > body text

How to create and delete indexes in MySQL

小云云
Release: 2018-03-20 15:10:00
Original
2316 people have browsed it

This article mainly shares with you the methods of creating and deleting indexes in MySQL. I hope it can help you.

1. Add index

(1)ALTER TABLE statement

1.PRIMARY  KEY(主键索引)
        mysql>ALTER  TABLE  `table_name`  ADD  PRIMARY  KEY (  `column`  ) 
2.UNIQUE(唯一索引)
        mysql>ALTER  TABLE  `table_name`  ADD  UNIQUE (`column` ) 
3.INDEX(普通索引)
        mysql>ALTER  TABLE  `table_name`  ADD  INDEX index_name (  `column`  )
4.FULLTEXT(全文索引)
        mysql>ALTER  TABLE  `table_name`  ADD  FULLTEXT ( `column` )
5.多列索引
        mysql>ALTER  TABLE  `table_name`  ADD  INDEX index_name (  `column1`,  `column2`,  `column3`  )
Copy after login

(2)CREATE INDEX statement

1.UNIQUE(唯一索引)
        mysql>CREATE UNIQUE INDEX index_name ON `table_name` (`column` ) 
2.INDEX(普通索引)
        mysql>CREATE INDEX index_name ON `table_name` (  `column`  )
3.多列索引
        mysql>CREATE INDEX index_name ON `table_name` (  `column1`,  `column2`,  `column3`  )
Copy after login

2. Delete index

1.PRIMARY  KEY(主键索引)
        mysql>ALTER  TABLE  `table_name`  DROP PRIMARY KEY 
3.INDEX(普通索引)或UNIQUE(唯一索引)
        mysql>ALTER  TABLE  `table_name`  DROP INDEX index_name
        mysql>DROP INDEX index_name ON `talbe_name`
Copy after login

Related recommendations:

How to create an index for a join table related to two tables in MySQL Detailed graphic and text explanation

What is an index? How to create an index in MySQL

mysql index creation and index deletion

The above is the detailed content of How to create and delete indexes 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!