MySQL我们可以对具有或条件的多个列有外键引用吗?

发布于 2025-02-03 10:36:22 字数 224 浏览 4 评论 0原文

我要将多个DB迁移到一个DB,所有这些DB都有相同的表格,问题是重复的键,因此,由于这个原因,我认为最简单的解决方案是在我的主表中使用ex_id,然后在子表中有一个外键,该键应引用idex_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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

地狱即天堂 2025-02-10 10:36:22

否。一个外键约束名称,它引用了哪个表和列,并且必须在每个行上引用相同的表和列。

我之所以说列,是因为某些约束是多列,而不是因为外键可以参考您选择的列。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文