Multiple Many-to-Many Relationships (Circular Relationship)

时间秒杀一切 提交于 2019-12-11 02:46:33

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/31687707/multiple-many-to-many-relationships-circular-relationship

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!