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;
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);
Three, display index
desc table name;
desc students_test;
show index from table name;
show index from students_test;
Fourth, delete the index
drop index index name on table name;
drop index name on students_test;