Cheng Plan--mysql Index

Source: Internet
Author: User
Tags mysql index

Definition:An index is a single, physical storage structure that sorts the values of one or more columns in a database table#为字段创建索引
#在表中的字段中创建索引
Mysql> Create IndexInd_score onscore (name); Query OK,0Rows Affected (0.03sec) Records:0Duplicates:0Warnings:0#查看索引mysql>ShowIndex fromscore;+-------+------------+-----------+--------------+-------------+-----------+-------------+----------+--------+ ------+------------+---------+---------------+| Table |Non_unique|Key_name|Seq_in_index|column_name|Collation|Cardinality|Sub_part|Packed| Null |Index_type|Comment|Index_comment|+-------+------------+-----------+--------------+-------------+-----------+-------------+----------+--------+- -----+------------+---------+---------------+|Score| 0 | PRIMARY | 1 |Id|A| 4 | NULL | NULL | |BTREE| | ||Score| 1 |Ind_score| 1 |Name|A| 4 | NULL | NULL | |BTREE| | |+-------+------------+-----------+--------------+-------------+-----------+-------------+----------+--------+- -----+------------+---------+---------------+2Rowsinch Set(0.00Sec

#也可以在创建表的时候创建索引

#删除索引

MySQL>dropindexon0 rows affected (0.01  0  0  0

#用alter创建/Delete Index

Mysql> Alter TableScoreAdd IndexInd_score (name); Query OK,0Rows Affected (0.02sec) Records:0Duplicates:0Warnings:0MySQL> Alter TableScoreDrop IndexInd_score; Query OK,0Rows Affected (0.01sec) Records:0Duplicates:0Warnings:0

#创建索引值唯一的索引 (the benefit is that data can be quickly queried by a unique index when there is a large number)

MySQL>Createuniqueindexon0 rows affected (  0.020  0  0

Cheng Plan--mysql Index

Related 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.