【十八,MySQL】进阶篇--索引语法

在这里插入图片描述

1,创建索引

create [unique | fulltext] index index_name on table_name (index_col_name,……);

2,查看索引

show index from table_name;

3,删除索引

drop index index_name on table_name;
create table tb_user(
    id int primary key auto_increment,
    name varchar(10),
    phone varchar(11),
    email varchar(50),
    profession varchar(50) comment '专业',
    age int ,
    gender char(1) ,
    status int,
    createtime date
)comment '用户表'charset = utf8;

drop table tb_user;
select * from tb_user;

insert into tb_user(id, name, phone, email, profession, age, gender, status, createtime) values
(1,'吕布','13512341234','bu-lv@qq.com','软件工程',25,'男',1,'2021-01-05');
insert into tb_user(id, name, phone, email, profession, age, gender, status, createtime) values
(2,'曹操','13512341232','cao-cao@qq.com','通讯工程',26,'男',1,'2020-02-12');

insert into tb_user(id, name, phone, email, profession, age, gender, status, createtime) values
(1,'吕布','13512341234','bu-lv@qq.com','软件工程',25,'男',1,'2021-01-05');
insert into tb_user(id, name, phone, email, profession, age, gender, status, createtime) values
(1,'吕布','13512341234','bu-lv@qq.com','软件工程',25,'男',1,'2021-01-05');
insert into tb_user(id, name, phone, email, profession, age, gender, status, createtime) values
(1,'吕布','13512341234','bu-lv@qq.com','软件工程',25,'男',1,'2021-01-05');
insert into tb_user(id, name, phone, email, profession, age, gender, status, createtime) values
(1,'吕布','13512341234','bu-lv@qq.com','软件工程',25,'男',1,'2021-01-05');
insert into tb_user(id, name, phone, email, profession, age, gender, status, createtime) values
(1,'吕布','13512341234','bu-lv@qq.com','软件工程',25,'男',1,'2021-01-05');
insert into tb_user(id, name, phone, email, profession, age, gender, status, createtime) values
(1,'吕布','13512341234','bu-lv@qq.com','软件工程',25,'男',1,'2021-01-05');
insert into tb_user(id, name, phone, email, profession, age, gender, status, createtime) values
(1,'吕布','13512341234','bu-lv@qq.com','软件工程',25,'男',1,'2021-01-05');

# 1,name字段为名字,该字段的值可能会重复,为该字段创建索引 创建的是常规索引,不需要在index前指定,在查看索引时,索引类型也是默认BTREE(其实是B+TREE)
create index index_name on tb_user(name);

# 2,phone字段为手机号,非空,且唯一,为该字段创建索引
create unique  index index_phone on tb_user(phone);

# 3,为profession,age,status创建联合索引,字段的顺序有讲究
create index lianhe_name on tb_user(profession,age,status);

# 4,为email建立合适的索引来提升查询的效率
create index index_email on tb_user(email);

# 查看索引
show index from tb_user;
# 删除索引
drop index index_name on tb_user;

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值