Mysql索引的查看,创建,删除

来源:互联网 发布:汇川plc编程电缆 编辑:程序博客网 时间:2024/06/04 20:06

一:在一张表的某一列或某几列上创建索引能加快查询速度,但需要注意的是更新的时候也需要更新索引,所以会导致加完索引后更新数据更慢了.所以最好将索引加到经常查询的列上,还需要注意的是,一张表的索引数量最好不要超过4个,索引数量太多同样会导致查询效率低.

二:搜索的索引列,不一定是所要选择的列.换句话说,最适合索引的列是出现在where字句中的列,或者连接字句中指定的列,而不是出现在select关键字后的选择列表中的列.

1.查看数据库中某一张表的索引;
show index from 表名;

2.创建索引为某一张表;
1).创建简单索引的语句:
create index 索引名称 on 表名称 (列名称)
例如:create index nameIndex on student (name)
2).创建唯一索引的语句:
create unique index 索引名称 on 表名称 (列名称)
例如: create unique index sexIndex on student (sex)
3).一个表创建多个索引
create index nameIndex on student (name1,name2)
4).当要求索引查出时排序(降序)
create index nameIndex on student (name desc)

3.删除某一张表上的索引
drop index 索引名 on 表名

原创粉丝点击