目录
创建索引
使用ALTER TABLE 语句创建索引
使用CREATE TABLE 语句创建索引
删除索引
使用ALTER TABLE 语句删除索引
使用DROP INDEX 语句删除索引
创建索引
1、创建表的同时,指定给某个字段创建索引(name)
create table cat(
id int not null AUTO_INCREMENT,
name varchar(30) not null,
age int not null,
PRIMARY KEY (id),
unique index indexname(name)
)
2、在已经存在的表,为表中的某个字段创建索引
使用ALTER TABLE 语句创建索引
1.执行语句
alter table cat add index catname(name)
2.show index 查看表中索引
show index from cat

3 explain关键字查看sql是否使用到了索引
EXPLAIN SELECT name from cat

创建唯一索引
alter table cat add index UniqiIdx(id)
使用CREATE TABLE 语句创建索引
创建普通索引:
create index catnameIndex on cat(name)
创建唯一索引:
create unique index UniqIdx on cat(id)
删除索引
使用ALTER TABLE 语句删除索引
alter table 表名 drop index 索引名
举例:alter table cat drop index catname
使用DROP INDEX 语句删除索引
drop index 索引名 on 表名



![【无需注册账号】只需两步, Ai Studio上也可以玩[ChatGPT]了](https://img-blog.csdnimg.cn/img_convert/b92a0899d329d252c5d708cc0a1df9e1.png)



![[附源码]Python计算机毕业设计SSM基于的校园失物招领平台(程序+LW)](https://img-blog.csdnimg.cn/eecb39d791844f34881801cb954f4124.png)





![[附源码]Python计算机毕业设计SSM基于的校园卡管理系统(程序+LW)](https://img-blog.csdnimg.cn/5dfcdd1a965e49f4bbd674a5b0639a12.png)

![[附源码]Python计算机毕业设计SSM基于的小型房屋租赁平台(程序+LW)](https://img-blog.csdnimg.cn/bae51dfea4914354a450e01f16af2e0c.png)



