我们在项目中要求存储数据库中实体的所有修订(更改历史记录)。目前,我们为此提出了两项建议:
例如「雇员」实体
设计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个实体需要维护修订版)。