The use of mysql database index

Insert picture description here

1. Classification of index

The purpose of the index is to speed up data retrieval (query).
Disadvantage: It
takes up physical storage space.
When the data in the table is updated, the index needs to be dynamically maintained, which reduces the data maintenance speed.

1. Ordinary index

characteristic

MUL can be NULL

format

index (field name)

2. Unique index

characteristic

UNI must only be NULL

format

unique (field name)

Second, the creation of the index

1. Created when creating a table

create table table name (
field name data type,
field name data type,
index (field name), ordinary index
index (field name),
unique (field name) unique index
);

create table students_test(id int primary key auto_increment,
   name varchar(20), 
   phone varchar(11), 
   index(name), 
   unique(phone))charset=utf8;

Insert picture description here

2. Add to existing table

create unique index index name on table name (field name);
create index index name on table name (field name);

create unique index name on students_test(name);
create index name on students_test(name);

Insert picture description here

Three, display index

desc table name;

desc students_test;

Insert picture description here

show index from table name;

show index from students_test;

Insert picture description here

Fourth, delete the index

drop index index name on table name;

drop index name on students_test;

Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_45875105/article/details/112212737