为什么我用add index(字段名) 出来显示key为MUL
mysql> create table test_7(username varchar(20) not null,id int unsigned);
Query OK, 0 rows affected (0.12 sec)
mysql> alter table test_7 add index uni_username(username);
Query OK, 0 rows affected (0.12 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc test_7;
+----------+------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+------------------+------+-----+---------+-------+
| username | varchar(20) | NO | MUL | NULL | |
| id | int(10) unsigned | YES | | NULL | |
+----------+------------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
mysql> show create table test_7;
+--------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table
|
+--------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| test_7 | CREATE TABLE `test_7` (
`username` varchar(20) NOT NULL,
`id` int(10) unsigned DEFAULT NULL,
KEY `uni_username` (`username`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 |
+--------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql>
我重建了一个test_7 也这样 MUL是什么 为什么我show create table 内容只有
KEY `uni_username` (`username`)
正常不是应该unique key xxxx吗
正在回答 回答被采纳积分+1
我只用的是alter table test_7 add index(name) 运行后显示的是key不是unique key。
现在我用alter table test_7 add unique key(name) 这样写就行了,这是为什么 key和unique key,MUL和UNI的区别是什么?
mysql> alter table test_7 add unique key(dress);
Query OK, 0 rows affected (0.14 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc test_7;
+----------+------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+------------------+------+-----+---------+-------+
| username | varchar(20) | NO | MUL | NULL | |
| id | int(10) unsigned | YES | | NULL | |
| dress | varchar(20) | YES | UNI | NULL | |
+----------+------------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
mysql> show create table test_7;
+--------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table
|
+--------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| test_7 | CREATE TABLE `test_7` (
`username` varchar(20) NOT NULL,
`id` int(10) unsigned DEFAULT NULL,
`dress` varchar(20) DEFAULT NULL,
UNIQUE KEY `dress` (`dress`),
KEY `uni_username` (`username`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 |
+--------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql>
- 参与学习 人
- 提交作业 626 份
- 解答问题 4930 个
想要学好Web后端开发的中流砥柱语言,本阶段为你轻松铺就扎实的基础,从前端网页布局的搭建到后台PHP开发,助你从零基础到掌握主流开发语言。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星