MySQL - 唯一的外键 [英] MySQL - Unique foreign key

查看:287
本文介绍了MySQL - 唯一的外键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须使其中一个外键独一无二。问题是,我从phpMyAdmin收到以下消息:

 
下面的索引似乎是相同的,其中一个应该被删除:consignmentnumber_id_UNIQUE,fk_consignments_consignmentnumbers2

所以我的问题是这样的:我应该打扰吗?是否真的很重要,没有这样的索引?

解决方案

使用键(主键,外键)的每一列都需要一个索引。相同的列是唯一的。您可能创建了两个索引(创建FK时创建一个,唯一约束创建一个索引)。如果是这种情况,只需删除其中一个索引即可。



DB维护两个等价索引是开销。


I have to make one of the foreign keys unique. The problem is, I am getting the following message from the phpMyAdmin:

The following indexes appear to be equal and one of them should be removed: consignmentnumber_id_UNIQUE, fk_consignments_consignmentnumbers2

So my question is this: should I be bothered? Is it really important not to have such indexes?

解决方案

Every column with an key (primary, foreign) needs an index. Same with column being unique. You probably created two indexes (one when creating FK and one on Unique constraint). If this is the case just drop one of those indexes.

It is overhead for the DB to maintain two equivalent indexes.

这篇关于MySQL - 唯一的外键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆