Mysql index types: PRIMARY, INDEX, UNIQUE, FULLTEXT, and SPAIAL? What are the applicable scenarios ?, Fulltextspaial
Mysql common indexes include: primary key index, unique index, common index, full-text index, and composite index.
Primary key (primary key index)Alter table 'table _ name' add primary key ('column ') UNIQUE (UNIQUE index) ALTER table 'table _ name' add unique ('column ')
INDEX (Common INDEX)Alter table 'table _ name' add index index_name ('column ') FULLTEXT (full-text INDEX) ALTER table 'table _ name' add fulltext ('column ')
Composite IndexAlter table 'table _ name' add index index_name ('column1 ', 'column2', 'column3 ')
Differences between various indexes in Mysql:
Common INDEX: the most basic INDEX with no restrictions
UNIQUE index: similar to "normal index", the difference is that the index column value must be UNIQUE, but null values are allowed.
PRIMARY Key Index (PRIMARY): It is a special unique index and does not allow null values.
Full-text index (FULLTEXT): it can be used only for MyISAM tables. It is very time-consuming to generate full-text indexes for retrieving text information in an article.
Composite Index: To improve mysql efficiency, you can create composite indexes following the "leftmost prefix" principle.
For exampleFor example, you are creating a membership card system for a mall.
This system has a membership table
The following fields are available:
Member ID INT
Member name VARCHAR (10)
Member ID number VARCHAR (18)
Member phone number VARCHAR (10)
Member Address VARCHAR (50)
Member remarks TEXT
The member number is used as the PRIMARY key and PRIMARY is used.
If you want to create an INDEX for the member name, it is a normal INDEX.
If you want to create an index for the member ID card number, you can select UNIQUE (UNIQUE, not allowed to be repeated)
Member remarks. If you need to create an index, you can select FULLTEXT for full-text search.
However, when FULLTEXT is used to search for a long article, it is the best.
It is used in short text. If there are only one or two lines of text, the normal INDEX is also acceptable.
Create index: create unique index indexName ON tableName (tableColumns (length ))
Syntax for deleting an INDEX: drop index index_name ON tableName