这应该在数据库中表示为 1 个表还是 3 个表?我和我的朋友对此有不同的看法,所以我想看看对此的一般看法。(也许这应该是对任一解决方案的投票?)
Create Table Order
// Basic fields of the table
- ID (Primary key)
- CustomerID (integer, with a FK)
- Quantity
- ProductID (integer, with a FK)
// Then depending on user selection, either these fields need to be specified
// (could be factored out to a separate table):
{
- InternalAccountID (integer, with a FK)
- InternalCompanyID (integer, with a FK)
}
// Or these (could be factored out to a separate table):
{
- ExternalAccountNumber (free text string)
- ExternalCompanyName (free text string)
- ExtraInformation (free text string)
}
1表方法:
优点:
- 性能(一个插入而不是两个,FK 检查,无连接)
- 可能占用更少的空间(额外的表有开销 + 索引 + 额外的 ID 字段)
- 一张桌子而不是三张
- 仅针对 2+3 个字段(或什么?)
缺点:
- 可为空的字段
- 可能额外的“类型”列(可以跳过)
- 打破 3NF (?)
利弊请及个人意见。:)
编辑:我尝试通过使用与实际使用不同的实体来简化示例,因此任何更改模型的建议都不会真正帮助我。即请更多地关注技术方面而不是领域模型。