处理三个表之间有两个一对多关系
我有一个三个表,A,B和C。A有很多B,B有很多C。设计主键和这两者之间的关系的最佳方法是什么。抱歉问一个设计问题,但我不知道是否使用
- 一个额外的表来映射 A(pkey) - B(pkey) - C(pkey) 或
- 两个额外的表来分别映射 AB 和 BC 或
- 使用外键关系不使用任何额外的表(如果是这样,请告诉我关键列应该如何出现)
非常感谢。
I have a three tables, A, B and C. A has many B, and B has many C. What is the best way design primary keys and relationship among these two. Sorry to ask a designing problem, but I don't know whether to use
- one extra table to map A(pkey) - B(pkey) - C(pkey) OR
- two exta tables to map A-B and B-C separately OR
- use foreign key relationships without using any extra tables (if so please tell me how the key columns should come)
Thank you very much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
选项 (3) 听起来最自然:
查询:
始终让数据库对数据中的逻辑关系进行建模,而不是相反!
Option (3) sounds like the most natural:
To query:
Always make your database model the logical relationships in your data, not the other way round!
我会用三个。一对多关系中不需要额外的表。多方拥有指向单方的外键。
I'd use three. THere's no need for additional tables in a 1:many relationship. The many-side holds a foreign key pointing to the one-side.
选项 3 是可行的方法。
Option 3 is the way to go.