This article uses examples to illustrate the types and basic usage of MySQL indexes. Share with you for your reference, the details are as follows: indexMySQL currently has the following main index types:
- General indexIs the most basic index, it has no restrictions. CREATE INDEX IndexName ON `TableName`(`field name`(length)) - Unique indexSimilar to the previous ordinary index, the difference is that the value of the index column must be unique, but null values are allowed. If it is a composite index, the combination of column values must be unique. CREATE UNIQUE INDEX indexName ON table(column(length)) - Primary key indexIt is a special unique index. A table can only have one primary key and no null values are allowed. Generally, the primary key index is created at the same time as the table is created. CREATE TABLE `table` ( `id` int(11) NOT NULL AUTO_INCREMENT , `title` char(255) NOT NULL , PRIMARY KEY (`id`) ); - Combined indexRefers to an index created on multiple fields. The index will be used only if the first field when the index is created is used in the query condition. Follow the leftmost prefix set when using a composite index ALTER TABLE `table` ADD INDEX name_city_age (name,city,age); - Full text indexIt is mainly used to find keywords in text rather than directly comparing with values in the index. The fulltext index is very different from other indexes. It is more like a search engine rather than a simple parameter match of a where statement. The fulltext index is used in conjunction with the match against operation, rather than the general where statement plus like. It can be used in create table, alter table, and create index, but currently only char, varchar, and text columns can be used to create full-text indexes. It is worth mentioning that when the amount of data is large, it is much faster to put the data into a table without a global index and then create a fulltext index with CREATE index than to create a fulltext index for a table first and then write the data. CREATE TABLE `table` ( `id` int(11) NOT NULL AUTO_INCREMENT , `title` char(255) CHARACTER NOT NULL , `content` text CHARACTER NULL , `time` int(10) NULL DEFAULT NULL , PRIMARY KEY (`id`), FULLTEXT (content) ); Readers who are interested in more MySQL-related content can check out the following topics on this site: "Summary of MySQL Index Operation Skills", "Summary of MySQL Common Functions", "Summary of MySQL Log Operation Skills", "Summary of MySQL Transaction Operation Skills", "Summary of MySQL Stored Procedure Skills" and "Summary of MySQL Database Lock-Related Skills". I hope this article will be helpful to everyone's MySQL database design. You may also be interested in:
|
<<: js to realize the rotation of web page pictures
MySQL v5.7.19 official version (32/64 bit install...
Preface In some cases, we only know the intranet ...
1 Create a user and specify the user's root p...
Thanks to the development of the Internet, we can...
Preface Engineers working in the Linux environmen...
Preface Learn MySQL to reorganize previous non-MK...
For historical reasons, MySQL replication is base...
1. Link layout of the new site homepage 1. The loc...
System: Ubuntu 16.04LTS 1\Download mysql-5.7.18-l...
This article uses an example to illustrate the ex...
Preface I am currently working on a high-quality ...
This article shares the specific code of NodeJS t...
When we edit a layout, we usually use horizontal ...
Table of contents Preface Install the graphics dr...
1. <div></div> and <span></s...