假设我有3张桌子,
Column(ID(Primary Key),name, created_by, description(FK), table_name)
ID | name | created_by | description | table_name
------------------------------------------
1 | c1 | nobody | 1 | A
------------------------------------------
2 | c2 | abc | 2 | B
Description(ID(Primary Key), data)
ID | Data
---------
1 | description1
---------
2 | description2
Formula(ID(Primary Key, name, column_id(Foreign Key))
ID | Name | column_id
---------------------
1 | f1 | 1
---------------------
2 | f2 | 2
每次列更改或公式表更改时,我都需要向拥有新版本的Column表添加版本控制。
我计划构建一个主表,该表将具有这样的列,
History_Column(ID(Primary Key), column_id, column_created_by, column_edited_by, column_desc, column_table_name, formula_name)
ID | column_id | column_created_by | column_edited_by | column_desc | column_table_name | formula_name
------------------------------------------------------------------------------------------------------
1 | 1 | nobody | nobody | description1 | A | f1
2 | 2 | abc | abc | description2 | B | f2
3 | 1 | nobody | abc | changed_data | A | f1
4 | 1 | nobody | cde | changed_data | B | f1
Description(ID(Primary Key), data)
ID | Data
---------
1 | changed_data
---------
2 | description2
Column(ID(Primary Key), created_by, edited_by, description(FK), table_name, version_id)
ID | created_by | edited_by | description | table_name | version_id
--------------------------------------------------------------------
1 | nobody | cde | 1 | B | 3
2 | abc | abc | 2 | B | 1
所有更改都将直接在表中更新,除非我将所有数据保存在历史表中。
这是一个好方法吗,我不确定如何处理适当的外键。有人可以帮我解决这个问题吗?