MySQL我们可以对具有或条件的多个列有外键引用吗?
我要将多个DB迁移到一个DB,所有这些DB都有相同的表格,问题是重复的键,因此,由于这个原因,我认为最简单的解决方案是在我的主表中使用ex_id
,然后在子表中有一个外键,该键应引用id
或ex_id
。
我们可以有这样的东西,还是任何更好的解决方案?
注意:我不想丢失任何数据,它们是真正的现场DB。
谢谢
I'm gonna migrate multiple DBs to one DB, all those DBs have same tables, the problem is duplicate keys, so for this reason I thought the easiest solution is to have ex_id
in my main tables and then have a foreign key in child tables that should reference either to id
or ex_id
.
Can we have something like that, or any better solution ?
Note: I do not want to lose any data, they are the real live DBs.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
否。一个外键约束名称,它引用了哪个表和列,并且必须在每个行上引用相同的表和列。
我之所以说列,是因为某些约束是多列,而不是因为外键可以参考您选择的列。
No. A foreign key constraint names exactly which table and column(s) it references, and it must reference the same table and column(s) on every row.
I say column(s) because some constraints are multi-column, not because the foreign key can reference your choice of column.