MySQL index classification and indexing command statement

MySQL Index Classification

There are single-valued index and two kinds of the composite index, concrete can be divided into the following:

  1. Primary key index:
    It is a special unique index, does not allow nulls. Usually at the same time create a primary key index when construction of the table
  2. General index:
    This is the most basic index, it does not have any restrictions, allow single repeat
create index idx_name on user(
name(20)
);
  1. Unique index:
    Similar to the general index, is different: the value of the index columns must be unique, but allow nulls (note different and primary key). If it is a composite index, a combination of the column value must be unique, and create a method similar to ordinary index
CREATE UNIQUE INDEX idx_email ON user(
email
);
  1. Full-text index
    MySQL supports full text indexing and search capabilities. MySQL full-text index of type FULLTEXT index. FULLTEXT indexes only for MyISAM tables; code as follows:
CREATE TABLE articles (
   id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
   title VARCHAR(200),
   body TEXT,
   FULLTEXT (title,body)
    );
mysql> SELECT * FROM articles WHERE MATCH (title,body) AGAINST ('database');
  1. Composite Index:
    i.e. an index containing a plurality of columns, as follows:
CREATE TABLE test (
    id INT NOT NULL,
    last_name CHAR(30) NOT NULL,
    first_name CHAR(30) NOT NULL,
    PRIMARY KEY (id),
    INDEX name (last_name,first_name)
);

Here Insert Picture Description

Use ALTER command:

Here Insert Picture Description

Published 217 original articles · won 125 Like · views 10000 +

Guess you like

Origin blog.csdn.net/qq_39885372/article/details/104164732