简体   繁体   中英

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. For example, say TableA has 5 rows -- 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? 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.

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. 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.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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