簡體   English   中英

創建新表與添加新字段

[英]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

然后我有兩種方法。

方法1:

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

方法2:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM