陷入数据库设计问题
假设我有以下表格:
GearType:滑雪板/头盔/鞋子/其他
GearModel:描述制造商、尺寸和 GearType
Gear :代表齿轮的物理实例,属于 GearModel 并描述其条形码、佩戴次数...
成员:可以为每个现有齿轮类型分配齿轮的人
GearAssignation:具有双 PK MemberId/GearTypeId,因此可以为每个齿轮类型为会员分配 0..1 个齿轮,也具有 FK GearId
我的问题是: 由于装备不能同时分配给超过 1 名会员, 如何在 Gear 和 GearAssignation 之间建立基数 1 到 0..1 的关系?
最好的情况是,我设法使用 Gear.Id 和 GearAssignation.GearId 之间的关系来做到这一点,并在 GearId 上使用唯一的键(记住它不能是 PK,因为有双重 PK MemberId/GearTypeId)。 但我很想摆脱那个英国,因为我的软件开发工具无法识别它。
根据建议,这是 SSMS 的图表:
对当前模型进行重大更改对我来说根本不是问题。 建议?
PS:不知道是否有帮助,我正在使用 Microsoft 的 SQL Server 2008
Say I have the following tables:
GearType : snowboard/helmet/shoes/whatever
GearModel : which describes the manufacturer, size, and GearType
Gear : represents a physical instance of a gear, belongs to a GearModel and describes its barcode, number of times it has been worn...
Member : a person who may be assigned a Gear for each existing geartype
GearAssignation : has a double PK MemberId/GearTypeId so a Member can be assigned 0..1 gear per geartype, also has FK GearId
My question is :
Since a Gear cannot be assigned to more than 1 Member at once,
how to make up a relation between Gear and GearAssignation of cardinality 1 to 0..1 ?
At best I managed to do this using a relation between Gear.Id and GearAssignation.GearId, with an unique key (remember it cannot be the PK because of the double PK MemberId/GearTypeId) on GearId.
But I'd love to get rid of that UK because my software development tool doesn't recognize it.
As suggested, here is the diagram from SSMS :
Bringing heavy changes to the current model is not a problem at all for me atm.
Suggestions ?
PS : dunno if it helps, I'm using Microsoft's SQL Server 2008
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我会通过在 Gear 中为当前分配给的 member_id 设置一个字段来实现此目的。
I'd do this by having a field in Gear for the member_id who it is currently assigned to.