mysql添加索引

什么情况下适合添加索引

  • 该字段数据量庞大;
  • 该字段很少的DML操作(由于索引也需要维护,DML操作多的话,也影响检索效率);
  • 该字段经常出现在where条件中;

注意:实际开发中会根据项目需求等综合因素来做调整,添加索引并不能保证一定能够提升检索效率,索引添加不当也有可能会导致效率降低。

 

 

创建索引

create index dept_dname_index on dept(dname);

注:这样就给dept表内的dname创建了dept_dname_index这个索引.

查看索引

show index from dept;

删除索引

drop index dept_dname_index on dept;

 

posted on 2018-08-07 18:59  董大志  阅读(180)  评论(0)    收藏  举报

导航