MySQL index types and syntax

Source: Internet
Author: User

MySQL index types and syntax

To view all the indexes on a single table: Show index from table name;

To build an index: Alter Table name Add index Normal index/unique unique index/fulltext full-text index/primary key primary key index + column name

Delete index:ALTER TABLE name DROP INDEX name;

  syntax:ALTER TABLE member DROP INDEX email;

Delete Note: To be deleted according to the index name Key_name;

1. Normal index: Index just to speed up the query

Create syntax: ALTER TABLE member ADD index Tel index name (tel);

Delete syntax: ALTER TABLE member DROP INDEX tel;

2. Unique index: Unique can not only speed up the query speed, while the values on the row can not be duplicated;

Create syntax: ALTER TABLE member add unique (email);

3. Primary KEY index: Primary key primary key cannot be duplicated;

Create syntax: ALTER TABLE member add primary key (ID); Do not add index name, directly add (column name), you can;

Delete syntax: ALTER TABLE member drop PRIMARY key;

    Primary key index differs from unique index: The primary key must be unique, the unique index is not necessarily a primary key, a table can have only one primary key, but may have more than one unique index;

4. Full-text index: fulltext

Create syntax: ALTER TABLE member add fulltext ftext(Intro);

Delete syntax: ALTER TABLE member DROP INDEX tel;

The full-text index is suitable for indexing fields with data type text;

Formatted Output index: Show index from member \g;

Index_type:btree BTREE Two fork Tree index mode

MySQL index types and syntax

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.