7. MySQL索引分类

7.1 单值索引

即一个索引只包含单个列,一个表可以有多个单列索引

7.2 唯一索引

索引列的值必须唯一,但允许有空值

7.3 主键索引

设定为主键后数据库会自动建立索引,innodb为聚簇索引

7.4 复合索引

即一个索引包含多个列

7.5 语法

# 查看索引
show index from table_name\G;

# 删除索引
drop index [indexName] on mytable;

# 随表一起创建
create table customer(
	...
	key(customer_name), # 单值索引
	unique(customer_name), # 唯一索引
    primary key(customer_name), # 主键索引
    key(customer_no,customer_name) # 复合索引
);

# 单独建索引
# 单值索引
create index idx_customer_name on customer(customer_name);

# 唯一索引
create unique index idx_customer_no on customer(customer_no);

# 主键索引
alter table customer add primary key customer(customer_no);

# 复合索引
create index idx_no_name on customer(customer_no,customer_name);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值