From 6c24dcb6adfab566427ba46bea1b16f9b043b22f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E4=BF=8A=E4=BC=9F?= <2421084001@qq.com> Date: Thu, 19 Oct 2023 10:32:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../1019\344\275\234\344\270\232.md" | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 "12\346\236\227\344\277\212\344\274\237/1019\344\275\234\344\270\232.md" diff --git "a/12\346\236\227\344\277\212\344\274\237/1019\344\275\234\344\270\232.md" "b/12\346\236\227\344\277\212\344\274\237/1019\344\275\234\344\270\232.md" new file mode 100644 index 0000000..ca5eba1 --- /dev/null +++ "b/12\346\236\227\344\277\212\344\274\237/1019\344\275\234\344\270\232.md" @@ -0,0 +1,53 @@ +index 索引 高效获取数据结构 + +普通索引:单纯提高效率 + +唯一索引:unique index 唯一索引只能够建立在数据不重复的列上,唯一约束,不能重复可以null,有多个唯一约束。 + +主键索引:primary key 唯一性,非空,不能重复,不能null,一个只能有一个主键 + +--------------- + +create index 索引名称 on 表名(列) + +----------------------------------------------------- + +alter table 表名 add index 索引名(列) + +--------------------------------------- + +在建表的同时也能一起建立索引 + +-------------------------------- + +drop index 索引名 on 表名 -- 删除 + +shou index from 表名 --查询 + +explain 用于查询某个语句的执行详情 + +explain select ··· from ··· --语句 + +---------------------------------------------- + +1.name字段为姓名字段,该字段的值可能会重复,为该字段创建索引。 + +create index tb_name on tb_user(name); + +2.phone手机号字段的值,是非空,且唯一的,为该字段创建唯一索引。 + +desc tb_user; + +create unique index tb_phone on tb_user(name); + +3.为profession、age、status创建联合索引。 + +create index tb_pas on tb_user(profession,age,status); + +4.为email建立合适的索引来提升查询效率。 + +create index tb_email on tb_user(email); + +5.查看tb_user表的所有的索引数据 + +show index from tb_user; \ No newline at end of file -- Gitee