For this type of problem, I save the current table and the history table.
The history table has the following additional columns:
- HistoryID
- EffectiveDate
- Endate
- VersionNumber
- Createdby
- Createdat
Valid and ending dates are the time interval in which the values ββare valid. The version simply increases with every change to the record. Identifier, CreateAt and CreatedBy are the columns that I put in almost every table in the database.
Typically, I keep the history table up-to-date with night tasks that compare tables, and then use MERGE to combine the data. An alternative is to transfer all changes to stored procedures and update both tables. Another alternative is to use triggers that detect when a change occurs. However, I shy away from triggers, preferring the first two alternatives.
I must admit that disk space is not a big consideration for these tables. Thus, there are no problems with storing data twice, once in the results once in the history. It would be just a minor tweak to keep only the history in the history table, with the current entries in the "current" table.
One of the disadvantages of this approach is the change in the structure of the base table. If you want to add a column, you need to add it to the history table, as well as to the base table.
source share