数据库索引基本知识(创建索引、删除索引、修改索引)

版权声明:本博文仅供学习、参考、技术讨论,版权归笔者/译者所有。 https://blog.csdn.net/qq_38025219/article/details/84198092

索引分类:

主键索引: 不能为null,唯一索引可以为null
单值索引: 单列,每个表可以有多个
唯一索引: 不能重复
复合索引: 多个列构成的索引,相当于二级目录
name,age 两个张三,再看年龄;

创建索引:

一、create 索引类型 索引名 on 表
单值:
create index dep_index on tb(dept);
唯一
create unique index name_index tb(name);
复合
create index dept_name-index tb(dep,name);

二、更新
单值:
alter table tb add index dep_index (dept);
唯一
alter table tb add unique index name_index (name);
复合
alter table tb add index dept_name-index (dep,name);

  DDL自动提交
  注意事项,主键默认主键索引

删除索引:
drop index 索引名 on 表名
show index from 表名

猜你喜欢

转载自blog.csdn.net/qq_38025219/article/details/84198092