Question

I have the challenge to design a new database using a RDBMS, Oracle, to be precise. In this database there will be one specific record/document which may span multiple tables.

With as little duplication as possible, I want to keep track of the changes made to this record, and offer a simple way to create altered copies of that record.

I don't want a history table that will sum up the changes in text, because I want to be able to fetch document x exactly the way it looked at time t. But I don't want to have a full copy for every history entry either.

Are there best practices or patterns how to achieve this?

I may have an idea how to solve this using a strategy mimicking git, but I wanted some opinions first before I go that road.

Was it helpful?

Solution

In Oracle 12c specifically there is a new feature called "temporal flashback queries" that serves exactly this purpose. (Similar features are available in other databases: DB2, SQL Server, Vertica to name a few.)

To enable temporal queries you:

  1. Ensure that each of the tables representing your document has a pair of dates indicating the start and end date (time) when a particular record was valid (active), and
  2. Keep historical records by not updating them in place but rather inserting new versions of the records, updating only the end dates of historical records.

You will then be able to issue queries against your tables that look much like SELECT whatever FROM mytable AS OF some_date, which would return the records that were active at the specified date.

You can read the detailed description here.

Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange
scroll top