这不是一个糟糕的设计,但您可能会发现这种设计更有用:
Attachment
AttachmentId (pkey)
Answer
AnswerId (pkey)
AttachmentId (fkey)
Action
ActionId (pkey)
AttachmentId (fkey)
这允许您拥有没有任何操作的附件,而无需设置数据值,NULL
并且 siple 连接显示同一附件的所有操作和答案,而不是条件连接
(伪代码)
select * from Attachment
outer join Answer on Answer.AttachmentId = Attachment.AttachmentId
outer join Action on Action.AttachmentId = Attachment.AttachmentId
如果操作/答案可以有多个与之关联的附件,那么您将对其进行修改以包含交叉连接:
Attachment
AttachmentId (pkey)
Answer
AnswerId (pkey)
Action
ActionId (pkey)
AttachmentAnswer
AttachmentAnswerId (pkey)
AttachmentId (fkey)
AnswerId (fkey)
AttachmentAction
AttachmentActionId (pkey)
AttachmentId (fkey)
ActionId (fkey)