7.表的索引

汉语字典
拼音 偏旁部首

数据库中的索引就是类似于目录。

select *** from t_student where senam = 'Apple';


每一张都带一个主键索引。即通过主键的查询比其他字段要快。

创建普通索引:
create index 索引名 on 表名(字段名);
create index in_a on t_studet(sphone);

创建唯一索引: (唯一索引要求字段的值不能重复)
create UNIQUE index 索引名 on 表名(字段);


多列索引
create index 索引名 on t_studet(字段1,字段2);

explain可以展示一个查询的过程。


explain select * from t_student where sname='Tea';

explain select * from t_student where sphone='123123213213';

增删的时候索引需要消耗时间,即不是索引越多越好,一般的只是在需要频繁查询的字段添加
一个索引。
show index from 表名: 显示当前表的所有索引
drop index 索引名 on 表名:删除索引

优化可查询的速度,但降低了增删的速度

posted @ 2019-04-04 19:11  makalo  阅读(159)  评论(0编辑  收藏  举报