Home > Database > Mysql Tutorial > body text

Introduction to mysql index types

王林
Release: 2020-06-16 17:56:05
forward
3220 people have browsed it

Introduction to mysql index types

Introduction to index types:

Primary key index

primary key() requires that the keyword cannot be repeated or null ,When adding primary key constraints and defining the primary key index, you cannot name

unique index

##unique index() requires that keywords cannot be repeated, and also add unique constraints

Normal index

index() has no requirement for keywords

Full text index

fulltext key() keyword The source is not the data of all fields, but the special keywords extracted from the fields: it can be a certain field or multiple fields, and multiple fields are called composite indexes.

Example:

建表:
creat table student(
    stu_id int unsigned not null auto_increment,
    name varchar(32) not null default '',
    phone char(11) not null default '',
    stu_code varchar(32) not null default '',
    stu_desc text,
    primary key ('stu_id'),     //主键索引
    unique index 'stu_code' ('stu_code'), //唯一索引
    index 'name_phone' ('name','phone'),  //普通索引,复合索引
    fulltext index 'stu_desc' ('stu_desc'), //全文索引) engine=myisam charset=utf8;

更新:
alert table student    add primary key ('stu_id'),     //主键索引
    add unique index 'stu_code' ('stu_code'), //唯一索引
    add index 'name_phone' ('name','phone'),  //普通索引,复合索引
    add fulltext index 'stu_desc' ('stu_desc'); //全文索引删除:
alert table sutdent
    drop primary key,
    drop index 'stu_code',
    drop index 'name_phone',
    drop index 'stu_desc';
Copy after login

Recommended tutorial:
mysql tutorial

The above is the detailed content of Introduction to mysql index types. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:juejin.im
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template