Click here to Skip to main content
15,887,812 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi,I have a five tables representing a many to many relation as follows:
------------------------------------------
1.labels
------------------------------------------
id (primary key)
label_key
label_value

------------------------------------------
2.resource_a
------------------------------------------
id (primary key)
instance_name

------------------------------------------
3.resource_b
------------------------------------------
id (primary key)
instance_name

------------------------------------------
4.resource_c
------------------------------------------
id (primary key)
instance_name

------------------------------------------
5.resource_d
------------------------------------------
id (primary key)
instance_name

What I have tried:

Labels table id respectively with the following four resource table instance_name is a many-to-many relationship, my idea is to establish a middle table, a foreign key field in the table among associated labels in the table id, another field don't do link, just instance_name storage field, but this kind of structure when adding data don't know how to join

please advice me
Thank you
Posted
Updated 6-Aug-18 6:08am
v2

1 solution

You didn't post any code showing us where your issue is which makes the question very generic. So I'll give you the generic answer.
The many-to-many relation typically involves the middle table that you mentioned but with the foreign key for each of the joined tables. It's tough to figure what you're going for with all the tables named 'resource_x' so let's consider Students and Classes (not the C#/C++ class, but the class that offers a course at school). A class can have many students in it, and a student can attend many classes. Your "Student_Class" table would have at least StudentId and ClassId, the foreign key for Student and Class respectively. Those two values can either be combined to make a composite key or it can have an additional field StudentClassId that is the IDENTITY for that table.

HTH, Mike
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900