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);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据给出的引用资料,MySQL索引可以按照四个角度进行分类。首先,按照数据结构可以分为B tree索引、Hash索引和Full-text索引。其次,按照物理存储可以分为聚簇索引(主键索引)和二级索引(辅助索引)。接着,按照字段特性可以分为主键索引、唯一索引、普通索引和前缀索引。最后,按照字段个数可以分为单列索引和联合索引(复合索引、组合索引)。组合索引也被称为复合索引或多列索引,它将多个列共同组成一个索引,可以通过这几个字段进行查询,但是只有在查询条件中使用了这些字段中的第一个字段时,索引才会被使用。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [mysql索引分类](https://blog.csdn.net/kking_edc/article/details/130795723)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [MySQL索引分类](https://blog.csdn.net/qq_38785977/article/details/126809064)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [MySQL - 索引类型详解](https://blog.csdn.net/weixin_42201180/article/details/125769741)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值