How to efficiently version records in an SQL database

后端 未结 4 989
伪装坚强ぢ
伪装坚强ぢ 2021-02-10 15:01

In at least one application, I have the need to keep old versions of records in a relational database. When something should be updated, instead a new copy would be added and th

4条回答
  •  爱一瞬间的悲伤
    2021-02-10 15:18

    If you need old data being part of your business logic then:

    • Save latest version in master table.(insert and update, delete will just change the status column)
    • Take snapshot when an update happens in detail table(before any update an snapshot will be created).

    revision history

    • Another alternative will be Event Sourcing pattern.

    If old data is just a trace log of changes then:

    • An Entity–attribute–value approach may come in handy. An implementation sample can be found here.

提交回复
热议问题