mysql多个key,我们如何在现有MySQL表的多个列上设置阿黛尔007主题曲
santorumPRIMARYKEY?
我们可以通过使⽤ADD关键字和ALTER TABLE语句在现有表的多个列上设置PRIMARY KEY约束。
⽰例
假设我们有⼀个表“ Room_allotment”,如下所⽰:
mysql> Create table Room_allotment(Id Int, Name Varchar(20), RoomNo Int);
mysql> Describe Room_allotment;
+--------+-------------+------+-----+---------+-------+近墨者黑
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
美俪阿萨娜
| Id | int(11) | YES | | NULL | |
| Name | varchar(20) | YES | | NULL | |
| RoomNo | int(11) | YES | | NULL | |
+--------+-------------+------+-----+---------+-------+
3 rows in t (0.11 c)
现在,我们可以使⽤以下查询在多个列“ id”和“ Name”上添加复合PRIMARY
KEYmysql> Alter Table Room_allotment ADD PRIMARY KEY(Id, Name);
Records: 0 Duplicates: 0 Warnings: 0
mysql> Describe Room_allotment;
雅思
+--------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
honey意思>broil| Id | int(11) | NO | PRI | 0 | |
| Name | varchar(20) | NO | PRI | | |
cut是什么意思英文| RoomNo | int(11) | YES | | NULL | |
+--------+-------------+------+-----+---------+-------+
edci3 rows in t (0.12 c)
从上⾯的结果集中可以看出,PRIMARY KEY已添加到多列中。sound是什么意思