且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

多个表中的相同外键

更新时间:2023-01-29 13:00:49

你不需要为它们命名不同的东西。您可以在FAMILY中拥有FAM_ID列,在DOCUMENTS中拥有FAM_ID列,在CONTACT中拥有FAM_ID列。

You don't need to name them different things. You can have a FAM_ID column in FAMILY, a FAM_ID column in DOCUMENTS and a FAM_ID column in CONTACT.

在这种情况下,到同样的事情。

In this case naming them the same thing makes it clear that they refer to the same thing. But, you could also come up with another naming convention of your own if you like.

例如,我使用的东西沿着 family_ID的行 c>, 文档表。

For example, I use something along the lines of family_ID in the family table, and contact_familyID, document_familyID when referring to it from the contact and document tables.

命名它们的唯一缺点是,我可以看到,是在做连接时,你不能只通过列名引用它们,你必须通过tablename.columnname别名或者引用它们。

The only downside to naming them the same, as far as I can see, is that when doing joins you can't just refer to them by column name, you have to alias them or refer to them by tablename.columnname.

编辑:我认为我找到了你的意思是不能同名。在单个表中添加外键关系的情况如下所示: http://bugs.mysql.com/bug.php?id=46363

I think I've found what you mean by not being able to have the same name. This is the case when you add a foreign key relationship within a single table, as described here: http://bugs.mysql.com/bug.php?id=46363