Take you to understand the mysql index type

Source: Internet
Author: User
Tags mysql index

There are many types of MySQL indexes, which are basically divided into four categories. The following describes the MySQL indexes for your reference. I hope you can have a deeper understanding of MySQL indexes.

MySQL indexes include:
(1) Common Index
This is the most basic index with no restrictions. It can be created in the following ways:
◆ Create an index
Create index indexName ON mytable (username (length ));
For CHAR and VARCHAR types, the length can be smaller than the actual length of the field; For BLOB and TEXT types, the length must be specified, the same below.
◆ Modify Table Structure
ALTER mytable add index [indexName] ON (username (length ))
◆ When creating a table, specify
Create table mytable (id int not null, username VARCHAR (16) not null, INDEX [indexName] (username (length )));
Syntax for deleting an index:
Drop index [indexName] ON mytable;
(2) unique index
It is similar to the previous normal index. The difference is that the value of the index column must be unique, but a null value is allowed. If it is a composite index, the combination of column values must be unique. It can be created in the following ways:
◆ Create an index
Create unique index indexName ON mytable (username (length ))
◆ Modify Table Structure
ALTER mytable add unique [indexName] ON (username (length ))
◆ When creating a table, specify
Create table mytable (id int not null, username VARCHAR (16) not null, UNIQUE [indexName] (username (length )));
(3) Primary Key Index
It is a special unique index and does not allow null values. Generally, when creating a table, you can create a primary key index at the same time:
Create table mytable (id int not null, username VARCHAR (16) not null, primary key (ID ));
Of course, you can also use the ALTER command. Remember: A table can only have one primary key.
(4) Composite Index
 

Implement ADO connection to MYSQL

How to Create a MySQL Stored Procedure

How to use mysql triggers

Three examples of mysql triggers

Mysql Aggregate functions

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.