MySQL - Unique foreign key(MySQL - 唯一外键)
问题描述
我必须使其中一个外键唯一.问题是,我从 phpMyAdmin 收到以下消息:
<上一页>以下索引似乎相等,应删除其中之一:consignmentnumber_id_UNIQUE、fk_consignments_consignmentnumbers2所以我的问题是:我应该被打扰吗?没有这样的索引真的很重要吗?
每个有键(主键、外键)的列都需要一个索引.与列是唯一的相同.您可能创建了两个索引(一个在创建 FK 时创建,一个在唯一约束上创建).如果是这种情况,只需删除其中一个索引.
数据库维护两个等效索引是开销.
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 - 唯一外键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:MySQL - 唯一外键


基础教程推荐
- 带有WHERE子句的LAG()函数 2022-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- 带更新的 sqlite CTE 2022-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01