惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Schneier on Security
有赞技术团队
有赞技术团队
T
The Blog of Author Tim Ferriss
F
Fortinet All Blogs
D
DataBreaches.Net
F
Full Disclosure
腾讯CDC
博客园 - 【当耐特】
MyScale Blog
MyScale Blog
Stack Overflow Blog
Stack Overflow Blog
小众软件
小众软件
Hugging Face - Blog
Hugging Face - Blog
Last Week in AI
Last Week in AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
爱范儿
爱范儿
The GitHub Blog
The GitHub Blog
Engineering at Meta
Engineering at Meta
大猫的无限游戏
大猫的无限游戏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
SegmentFault 最新的问题
The Register - Security
The Register - Security
WordPress大学
WordPress大学
博客园 - 聂微东
雷峰网
雷峰网
J
Java Code Geeks
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Privacy International News Feed
酷 壳 – CoolShell
酷 壳 – CoolShell
A
Arctic Wolf
Scott Helme
Scott Helme
C
Cyber Attacks, Cyber Crime and Cyber Security
T
Tor Project blog
博客园 - 三生石上(FineUI控件)
Know Your Adversary
Know Your Adversary
AWS News Blog
AWS News Blog
G
Google Developers Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
CERT Recently Published Vulnerability Notes
O
OpenAI News
Project Zero
Project Zero
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Application and Cybersecurity Blog
Application and Cybersecurity Blog
云风的 BLOG
云风的 BLOG
N
News and Events Feed by Topic
MongoDB | Blog
MongoDB | Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Microsoft Security Blog
Microsoft Security Blog
Cisco Talos Blog
Cisco Talos Blog
P
Palo Alto Networks Blog
Schneier on Security
Schneier on Security

博客园 - simhare

Fix “Windows cannot access the specified device path or file” Error Domain Space mysql 登录后 修改密码 git delete repository php - func_get_args mysql show create table `tablename` 查看建表语句 zend framework assumptions linux vsftpd linux chkconfig pkill kill 看看自己是谁 linux 本地编码-如何解决乱码 linux添加用户-例如oracle 博文阅读密码验证 - 博客园 yum 只下载不安装 mysql netstat linux pts tty linux pts Linux 启动 进入单用户模式 其他用户无法连接 apache start stop
mysql key mul - 看不懂
simhare · 2013-05-16 · via 博客园 - simhare
http://dev.mysql.com/doc/refman/5.1/en/show-columns.html

The Key field indicates whether the column is indexed: 
If Key is empty, the column either is not indexed or is indexed only as a secondary column in a multiple-column, non-unique index. 
If Key is PRI, the column is a PRIMARY KEY or is one of the columns in a multiple-column PRIMARY KEY. 
If Key is UNI, the column is the first column of a unique-valued index that cannot contain NULL values. 
If Key is MUL, multiple occurrences of a given value are allowed within the column. 

The column is the first column of a non-unique index 
or a unique-valued index that can contain NULL values. 
If more than one of the Key values applies to a given column of a table, 
Key displays the one with the highest priority, in the order PRI, UNI, MUL. 

A UNIQUE index may be displayed as PRI if it cannot contain NULL values and there is no PRIMARY KEY in the table.

A UNIQUE index may display as MUL if several columns form a composite UNIQUE index;
although the combination of the columns is unique, each column can still hold multiple occurrences of a given value.

当我们在desc 表名;的时候,有一个Key值,表示该列是否含有索引
假设表结构如下所示

[PHP]
mysql> desc aa;
+-------+---------+------+-----+---------+-------+
| Field | Type    | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| id    | int(11) | YES  |     | NULL    |       |
+-------+---------+------+-----+---------+-------+
| xx    | int(11) | YES  | PRI | NULL    |       |
+-------+---------+------+-----+---------+-------+
| yy    | int(11) | YES  | UNI | NULL    |       |
+-------+---------+------+-----+---------+-------+
| zz    | int(11) | YES  | MUL | NULL    |       |
+-------+---------+------+-----+---------+-------+

1 row in set (0.00 sec)
[/PHP]
我们看到Key那一栏,可能会有4种值,即'啥也没有','PRI','UNI','MUL'
1. 如果Key是空的, 那么该列值的可以重复, 表示该列没有索引, 或者是一个非唯一的复合索引的非前导列
2. 如果Key是PRI,  那么该列是主键的组成部分
3. 如果Key是UNI,  那么该列是一个唯一值索引的第一列(前导列),并别不能含有空值(NULL)
4. 如果Key是MUL,  那么该列的值可以重复, 该列是一个非唯一索引的前导列(第一列)或者是一个唯一性索引的组成部分但是可以含有空值NULL

如果对于一个列的定义,同时满足上述4种情况的多种,比如一个列既是PRI,又是UNI
那么"desc 表名"的时候,显示的Key值按照优先级来显示 PRI->UNI->MUL
那么此时,显示PRI

一个唯一性索引列可以显示为PRI,并且该列不能含有空值,同时该表没有主键

一个唯一性索引列可以显示为MUL, 如果多列构成了一个唯一性复合索引
因为虽然索引的多列组合是唯一的,比如ID+NAME是唯一的,但是没一个单独的列依然可以有重复的值
只要ID+NAME是唯一的即可