简体   繁体   English

基于多个行ID的外键

[英]Foreign key based on multiple row ids

I'm trying to figure out how to store a combination of id fields as a foreign key in another table. 我试图弄清楚如何将id字段的组合作为外键存储在另一个表中。 For example, say TableA has 5 rows -- Ids 1-5. 例如,假设TableA有5行-IDS 1-5。

Without using a comma separated field is there a way I can make rows in TableB based off different combinations of TableA's ids? 如果不使用逗号分隔的字段,是否可以基于TableA的ID的不同组合在TableB中创建行? For example rows[1,3], rows[2,3], rows[1], rows[2,3,4] -- the thing throwing me off is it will always be a variable number of row ids that I am putting together. 例如rows [1,3],rows [2,3],rows [1],rows [2,3,4]-让我失望的是,它将永远是我可变数目的行id放在一起。

Is a comma separated field the only way to accomplish this? 逗号分隔的字段是完成此操作的唯一方法吗?

Thanks for any help or pointers... 感谢您的帮助或指点...

You're describing a many-to-many relationship between TableA and TableB. 您正在描述TableA和TableB之间的多对多关系。 You should introduce a third table to resolve this. 您应该引入第三张表来解决此问题。 This new table consists of two foreign keys, one referencing the ID from TableA and one from TableB. 此新表由两个外键组成,一个外键引用TableA的ID,一个引用TableB的ID。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM