MySQL index creation and deletion display

index:

Unique index: the
index value is unique, and at most one value is allowed to be empty.
Single-column index/normal index/single-value index:
an index contains only one column, and a table can have multiple single-value indexes.
Composite index:
an index contains multiple columns.
Primary key index
The index is automatically created when the primary key is established, and the index value cannot be empty. Innodb is a clustered index.
Full-text indexing
supports full-text search on the columns that define the index, allowing the insertion of duplicate values ​​and null values ​​in these indexed columns. Can be created on a column of type char varchar text. MySQL only supports full-text indexing with MyISAM engine.

The pros and cons of indexing

1 Advantages: greatly speed up query speed
2 Disadvantages: i Maintaining indexes requires database resources
ii Indexes require disk space
iii When adding, deleting, modifying, and querying table data, indexes need to be maintained, which leads to a waste of time

Index operation

#建表时创建普通索引
create table t_user(id varchar(20) primary key,name varchar(20),key(name));

#建表后创建普通索引
create index name_index on t_user(name);

#删除索引
drop index name_index on t_user

#显示索引
show index from t_user

#建表时创建唯一索引
create table t_user (
	id varchar(10) PRIMARY key,
	name varchar(2) ,unique(name)
);

#建表后创建唯一索引
create unique index name_index on t_user(name); 

#建表时创建复合索引
create table t_user (
	id VARCHAR(3) primary key,
	name varchar(3),
	age int(3),
	sex varchar(1),
	key(name,age,sex)
 );

 #建表后创建复合索引
 create index name_age_sex_index on t_user(name,age,sex)

Guess you like

Origin blog.csdn.net/weixin_49035356/article/details/112303197