简体   繁体   中英

Multiple Many-to-Many Relationships (Circular Relationship)

OK, I'm new to programming things, mainly learned myself by reading sites.... but I'm looking for an answer I haven't found fully explained anywhere.

I have three tables in a database: - Parts - Tools - Machines

I have read many instances of two junction tables connecting these three tables, but can this be circular, and I have three junction tables connecting the three info tables?

These are all Many-to-Many relationships.... for example:

Part A and B are both made from Tool 1 Part A is also made from Tool 2 Tool 1 can fit in Machine X and Y and Z Part A can only go in Machine X and Z Part B can only go in machine X and Y

Does this "circular" reference of junction tables work?

I'm thinking I need to have a: Part-to-Tool JCT Tool-to-Machine JCT Machine-to Part JCT

This makes a nice round relationship link... and I guess I haven't found any examples showing this online anywhere.

Any help would be appreciated!

You need to set up tables like the following:

tblPart - records for parts A and B

tblTool - records for tools 1 and 2

tblMachine - records for machines X, Y and Z

tblToolPart (fields: ToolId, PartId) - records 1, A; 1, B; 2, A.

tblPartMachine (fields: PartId, MachineId) - records A, X; A, Z; B, X; B,Y.

tblMachineTool (fields: MachineId, PartId) - records X, 1; Y, 1; Z, 1.

Don't know if this is clear enough to get the idea over, but with these 6 tables you can begin building queries to import whatever relationships you're interested in.

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