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)
}
一张表的方法:
优点:
- 性能(相对于两张表,外键检查和无需连接只需要插入一次)
- 可能占用更少的空间(额外的表有开销+索引+额外的ID字段)
- 只有一张表
- 几乎不值得为了2+3个字段(或什么?)而将其拆分成新表
缺点:
- 可为空的字段
- 可能需要额外的“类型”列(可以跳过)
- 破坏第三范式(?)
请提供优缺点以及个人意见。:)
编辑:我尝试通过使用不同的实体来简化示例,所以任何修改模型的建议都不会真正帮助我。即请关注技术方面而非领域模型。