[英]Creating new table vs adding new field
我有以下数据:
time | No fabric|BangloreSilk|Chanderi|.... <- fabric types
--------------------------------------------
01/15 | 40 | 25 |...
02/15 | 45 | 30 |...
..... | ... | ... |...
time | No fabric|BangloreSilk|Chanderi|.... <- fabric types
--------------------------------------------
01/15 | 40 | 25 |...
02/15 | 45 | 30 |...
..... | ... | ... |...
此处,两种数据的结构类型列表将相同。
现在添加这些数据,我创建了以下表格:
fabric_type
id int
fabric_type_name varchar
然后我有两种方法。
fabric_cost
id int
fabric_type_id int (foreign key to fabric_type)
cost int
deying_cost
id int
fabric_type_id int (foreign key to fabric_type)
cost int
fabric_overall_cost
id int
fabric_type_id int (foreign key to fabric_type)
cost int
fabric_or_dyeing bit (to represent 0 for fabric cost and 1 for dyeing cost)
现在的问题是哪种方法会更好?
也许您可以创建另一个表cost_subjects
cost_subjects
id byte
subject varchar
费用
id int
fabric_type_id int (foreign key to fabric_type)
cost int
cost_subject byte (foreign key to cost_subjects table)
然后,您可以扩展表格以包含更多的主题,以包括布料成本
这确实取决于您的要求。 还有其他仅对fabric_cost
表唯一的列吗? 是否有其他列仅对dyeing_cost
表唯一? 这意味着您的2张桌子会独立增长吗? 如果是,则方法1更好。 否则,方法2更好,因为您无需在2个单独的表上进行CRUD(以便于维护)。 另一种方法是:
id int
fabric_type_id int (foreign key to fabric_type)
fabric_cost float/double/decimal
dyeing_cost float/double/decimal
第三种方法是如果您同时拥有这两种成本。 您可能不希望将int
用于成本。 同样,这取决于您的要求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.