我们在项目中需要将实体的所有修订(更改历史记录)存储在数据库中。目前,我们有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)"
设计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, .., ..)"
还有其他方法可以做到这一点吗?
“设计1”的问题在于,每次需要访问数据时,我们都必须解析XML。这将减慢该过程的速度,并增加一些限制,例如我们无法在修订数据字段上添加联接。
“设计2”的问题在于,我们必须在所有实体上重复每个字段(我们要维护其约70-80个实体的修订版)。