创建新表与添加新字段 [英] Creating new table vs adding new field

查看:79
本文介绍了创建新表与添加新字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下数据:



布料成本

< pre lang =text>时间|无面料| BangloreSilk | Chanderi | ....< - 面料类型
------------------------------ --------------
01/15 | 40 | 25 | ...
02/15 | 45 | 30 | ...
..... | ...... | ... | ...





染色成本

时间|无面料| BangloreSilk | Chanderi | ....<  - 面料类型
------------------------------ --------------
01/15 | 40 | 25 | ...
02/15 | 45 | 30 | ...
..... | ...... | ... | ...



这两种数据的结构类型列表相同。




现在我添加以下表格创建的数据:



fabric_type

 id int 
fabric_type_name varchar





然后我有两种方法。

方法1:



< b> fabric_cost


 id int 
fabric_type_id int(fabric_type的外键)



cost int



deying_cost

 id int 
fabric_type_id int(fabric_type的外键)
cost int







方法2:



fabric_overall_cost



 id int 
fabric_type_id int(fabric_type的外键)
cost int
fabric_or_dyeing bit(代表0代表织物成本,1代表染色成本)





现在的问题是哪种方法会更好?

解决方案

我会用3表

1. FabricType

2. FabricCost

3. CostType



成本类型表你可以有两个现在,如果需要,您可以在以后添加更多。

成本类型和FabricType的主键可以在Fabric成本表记录中用作外键。


I am having following data :

Fabric Cost

time     |   No fabric|BangloreSilk|Chanderi|.... <- fabric types
--------------------------------------------
01/15    |         40 |         25 |...
02/15    |         45 |         30 |...
.....    |        ... |        ... |...



Dyeing Cost

time     |   No fabric|BangloreSilk|Chanderi|.... <- fabric types
--------------------------------------------
01/15    |         40 |         25 |...
02/15    |         45 |         30 |...
.....    |        ... |        ... |...


And here list of fabric types will be same for both the data.



Now to add this data I created following tables :

fabric_type

id                  int
fabric_type_name    varchar



And then I have two approaches .
Approach 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




Approach 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)



Now the question is which approach will be better??

解决方案

I would have use 3 table
1. FabricType
2. FabricCost
3. CostType

Cost type table you can have two entries now, you can add more in future if needed.
Primary Key of Cost Type and FabricType can used in Fabric cost table record as foreign keys.


这篇关于创建新表与添加新字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆