You are essentially trying to represent inheritance in a relational database.
You have two "classes" which are similar in some ways, and different in others. My suggestion is to create a table to act as a parent to both tbl_expanditures
and tbl_fixed_expanditures
.
Here's what I would do:
+------------------+
| tbl_expenditures |
+------------------+
| id |
+------------------+
+------------------------+
| tbl_fixed_expenditures |
+------------------------+
| id |
| expenditureId |
| ... |
+------------------------+
+---------------------------+
| tbl_variable_expenditures |
+---------------------------+
| id |
| expenditureId |
| ... |
+---------------------------+
...where tbl_fixed_expenditures.expenditureId
and tbl_variable_expenditures.expenditureId
both have a reference to tbl_expenditures.id
.
This way, when you need to refer to them simply as "expenditures" (for example, in your transaction table), you can reference tbl_expenditures
, and when you need information that is unique to either fixed or variable expenditures, you can refer to the "child" tables.
这是关系数据库中非常常见的问题,有多种处理方法,每种方法各有利弊。IBM 有一篇非常好的文章概述了这些选项,我强烈推荐它进一步阅读:
http://www.ibm.com/developerworks/library/ws-mapping-to-rdb/