什么会更好,表现明智?
一个包含多个外键和很多行的表
OR
有几个表,其中一个外键,每个表的数据较少。
示例:
我想创建一个表格,其中包含用户右侧的注释,每个注释将与另一个表格相关联。 在一个选项上它将是
Notes(ID,Text,CustomerID,AccountID,UserID,AnotherID) 其中包含每个不相关的外键的空值,所以:
ID Text CustomerID AccountID UserID AnotherID
1 "Call James" 1 null null null
2 "Call Havale" null 2 null null
3 "Call Shimi" null null 4556 null
另一个选项是打开单独的表,这些表将为每个表键入外键:
AccountNotes(ID, Text, AccountID)
CustomerNotes(ID, Text, CustomerID)
UserNotes(ID, Text, UserID), etc...
最后一个选项是将它视为多对多关系,尽管它不是(Notes_to_Accounts(NoteID,AccountID)
表,例如..)。
我在这里找到的所有答案都是关于一个表格,其中有几个列表,列表中有很少的小表,这不是我想要解决的问题。
答案 0 :(得分:1)
提供第三个选项,但对于简单实体(一个文本字段)来说可能太复杂了:
Notes(Id, Text)
AccountNotes(AccountId, NoteId)
CustomerNotes(CustomerId, NoteId)