MySQL社区

 找回密码
 注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

搜索
查看: 1534|回复: 1

[索引] 创建普通索引的一个疑问

[复制链接]
发表于 2016-11-9 11:15:38 | 显示全部楼层 |阅读模式
mysql> desc student;               
+---------+-------------+------+-----+---------+-------+
| Field   | Type        | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| stuno   | int(11)     | YES  |     | NULL    |       |
| stuname | varchar(60) | YES  |     | NULL    |       |
+---------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

mysql> create index sNoIdx on student(stuno);                    ----->只为一个字段stuno加了普通索引
Query OK, 0 rows affected (0.12 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> desc student;               
+---------+-------------+------+-----+---------+-------+
| Field   | Type        | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| stuno   | int(11)     | YES  | MUL | NULL    |       |                     -----------为什么却显示的是复合索引      ???
| stuname | varchar(60) | YES  |     | NULL    |       |
+---------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

发表于 2016-11-10 13:49:01 | 显示全部楼层
Key是MUL, 那么该列的值可以重复, 该列是一个非唯一索引的前导列(第一列)或者是一个唯一性索引的组成部分但是可以含有空值NULL;
并不一定是复合索引,也可以是可以为空的单列索引,就如你建的索引。

一般查看表中已经存在 index:show index from table_name;

参考自:MySQL索引操作 http://www.data.5helpyou.com/article259.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|申请友链|小黑屋|Archiver|手机版|MySQL社区 ( 京ICP备07012489号   
联系人:周生; 联系电话:13911732319

GMT+8, 2024-4-18 12:35 , Processed in 0.064965 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表