MySQL creates, recreates, queries, and deletes indexes.

Source: Internet
Author: User
1. You can create an index in the CREATETABLE statement, or use CREATEINDEX or ALTERTABLE to add an index to the table. The following command statement shows how to create a primary key INDEX (PRIMARYKEY), a Union INDEX (UNIQUE), and a general INDEX (INDEX. MysqlALTERTABLE 'table _ name' AD

1. You can CREATE an INDEX in the create table statement, or use create index or alter table to add an INDEX to the TABLE. The following command statements demonstrate how to create a primary key index, a unique index, and an INDEX. Mysql> alter table 'table _ name' AD

1. Create an index

You can CREATE an INDEX in the create table statement, or use the create index or alter table statement to add an INDEX to the TABLE. The following command statements demonstrate how to create a primary key index, a unique index, and an INDEX.
Mysql> alter table 'table _ name' add index | UNIQUE | primary key | 'index _ name' (column list );
Mysql> CREATE [UNIQUE] index'index _ name' ON 'table _ name' (column_list );

2. Re-Indexing

Rebuilding indexes is often used in routine database maintenance operations. After the database has been running for a long time, the indexes may be damaged, and reconstruction is required. Re-indexing data can improve the retrieval efficiency.
Mysql> repair table 'table _ name' QUICK;

3. query data table Indexes

Mysql> show index from | IN 'table _ name ';

4. delete an index

You can use the alter table or drop index statement to delete an INDEX. Drop index can be processed as a statement in alter table. The format is as follows:
Mysql> DROP index 'index _ name' ON 'table _ name' (column list );
Mysql> alter table 'table _ name' drop index | UNIQUE | primary key 'index _ name' (column list );

Original article address: MySQL creates an index, re-creates an index, queries an index, and deletes an index. Thanks to the original author for sharing this article.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.