How to efficiently version records in an SQL database

后端 未结 4 1914
日久生厌
日久生厌 2021-02-10 14:41

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:20

    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.

提交回复
热议问题