From a8bc95c1d7e170c2eee70d18dd57f633827010c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=B8=85=E7=BF=94?= <3371439772@qq.com> Date: Thu, 19 Oct 2023 12:44:49 +0800 Subject: [PATCH] =?UTF-8?q?10=E6=9C=8818=E6=97=A5=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...18\346\227\245\344\275\234\344\270\232.md" | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 "52\345\217\267 \347\250\213\345\270\205\347\277\224/10\346\234\21018\346\227\245\344\275\234\344\270\232.md" diff --git "a/52\345\217\267 \347\250\213\345\270\205\347\277\224/10\346\234\21018\346\227\245\344\275\234\344\270\232.md" "b/52\345\217\267 \347\250\213\345\270\205\347\277\224/10\346\234\21018\346\227\245\344\275\234\344\270\232.md" new file mode 100644 index 0000000..c48612b --- /dev/null +++ "b/52\345\217\267 \347\250\213\345\270\205\347\277\224/10\346\234\21018\346\227\245\344\275\234\344\270\232.md" @@ -0,0 +1,49 @@ + + + + +## 索引的分类 + +单列索引:一个索引建立在一个列上,一张表可以拥有多个单列索引 + +- 普通索引:单纯地为了提高搜索效率 index +- 唯一索引:unique index,唯一索引只能够建立在数据不重复的列上 ,唯一约束 ,不能重复,可以null,有多个唯一索引 +- 主键索引:primary key唯一性、非空,主键约束 ,不能重复,也不能null,一个只能有一个主键 + +联合索引:可以同时为多个列创建一个索引 + +全文索引(了解) + + + +## 单列索引 + +#### 创建索引(普通索引) + +这是最基本的索引,它没有任何限制。它有以下几种创建方式: + +-- 方式一和二是给现成表加索引 + +方式一:直接在已有表中创建索引 + +```sql +create index 索引名 on 表名(列名) -- 直接删除索引 drop index 索引名 on 表名; 这种不能用来创建主键索引 +``` + +方式二:修改表结构追加普通索引 + +```sql +alter table 表名 add index 索引名(列名); -- 修改表结构删除索引 alter table 表名 drop index 索引名; +``` + +方式三:创建表的时候直接指定 + +```sql +create table 表名( + aaa int primary key, + bbb varchar(20), + index 索引名 (列名) -- 以这种模式定义的索引,可以不指定索引名称。 + primary key(列名) +); +``` + -- Gitee