/*
索引基本语法
1、索引常见方式一 建表是创建
create table 表名(
列1 数据类型 约束,
列2 数据类型 约束,
index 索引名(列名(数据类型(长度)))
)
2、索引创建方式二 建表后创建 使用create
create index 索引名 on 表名(列名(数据类型(长度)))
3、索引创建方式三 建表后创建 使用alter 修改增加
alter table 表名 add index 索引名(列名(数据类型(长度)))、
4、查询索引 show index from 表名;
5、删除 drop index i_name on 表名;
*/
-- 索引创建方式一 建表时创建
create table t_test1(
id int not null,
tname varchar(20) not null,
index i_name(tname)
)
-- 索引创建方式二 建表后创建 使用create
-- 索引创建方式三 建表
-- show index from 表名;
show index from t_test1;
-- 删除
drop index i_name on t_test1;
show index from t_test1;
create unique index i_email on student(email);
-- 查询结果 key 值为索引名 如果key值为null 那么就没索引
explain select * from student stu where stu.email = 'cr@it.com';
MySQL 索引
最新推荐文章于 2023-07-20 19:49:48 发布