我们在项目中要求存储数据库中实体的所有修订(更改历史记录).目前我们有2个设计方案:
例如,对于"员工"实体
设计1:
-- Holds Employee Entity
"Employees (EmployeeId, FirstName, LastName, DepartmentId, .., ..)"
-- Holds the Employee Revisions in Xml. The RevisionXML will contain
-- all data of that particular EmployeeId
"EmployeeHistories (EmployeeId, DateModified, RevisionXML)"
Run Code Online (Sandbox Code Playgroud)
设计2:
-- Holds Employee Entity
"Employees (EmployeeId, FirstName, LastName, DepartmentId, .., ..)"
-- In this approach we have basically duplicated all the fields on Employees
-- in the EmployeeHistories and storing the revision data.
"EmployeeHistories (EmployeeId, RevisionId, DateModified, FirstName,
LastName, DepartmentId, .., ..)"
Run Code Online (Sandbox Code Playgroud)
有没有其他办法做这件事? …
这是一个虚构的场景,其中包含一些填充数据.出于税收目的,我的虚构公司必须保留历史数据的记录.出于这个原因,我在表格中添加了一个版本列.
TABLE EMPLOYEE: (with personal commentary)
|ID | VERSION | NAME | Position | PAY |
+---+---------+------------+----------+-----+
| 1 | 1 | John Doe | Owner | 100 | Started company
| 1 | 2 | John Doe | Owner | 80 | Pay cut to hire a coder
| 2 | 1 | Mark May | Coder | 20 | Hire said coder
| 2 | 2 | Mark May | Coder | 30 | Productive coder gets raise …Run Code Online (Sandbox Code Playgroud)