您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

我们如何创建多列UNIQUE索引?

2026/1/1 17:28:14发布50次查看
为了创建多列 unique 索引,我们需要在多个列上指定索引名称。以下示例将在“employee”表的“empid”、“first_name”、“last_name”列上创建名为“id_fname_lname”的多列索引 -
mysql> create unique index id_fname_lname on employee(empid,first_name,last_name);query ok, 0 rows affected (0.41 sec)records: 0 duplicates: 0 warnings: 0mysql> describe employee;+------------+-------------+------+-----+---------+-------+| field | type | null | key | default | extra |+------------+-------------+------+-----+---------+-------+| empid | int(11) | yes | mul | null | || first_name | varchar(20) | yes | | null | || last_name | varchar(20) | yes | | null | |+------------+-------------+------+-----+---------+-------+3 rows in set (0.12 sec)
从上面查询的结果集中,我们可以看到表上定义了多重索引。忘记有关索引的详细信息,我们可以运行以下查询 -
mysql> show index from employee\g*************************** 1. row ***************************table: employeenon_unique: 0key_name: id_fname_lnameseq_in_index: 1column_name: empidcollation: acardinality: 0sub_part: nullpacked: nullnull: yesindex_type: btreecomment:index_comment:*************************** 2. row ***************************table: employeenon_unique: 0key_name: id_fname_lnameseq_in_index: 2column_name: first_namecollation: acardinality: 0sub_part: nullpacked: nullnull: yesindex_type: btreecomment:index_comment:*************************** 3. row ***************************table: employeenon_unique: 0key_name: id_fname_lnameseq_in_index: 3column_name: last_namecollation: acardinality: 0sub_part: nullpacked: nullnull: yesindex_type: btreecomment:index_comment:3 rows in set (0.00 sec)
从上面的结果集中可以看出,‘key_name’字段中的值是相同的,因为我们已经在表的所有列上创建了多列索引。
以上就是我们如何创建多列unique索引?的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product