Versioning in SQL Tables - how to handle it?

前端 未结 7 1227
囚心锁ツ
囚心锁ツ 2021-01-30 08:50

Here\'s a fictional scenario with some populated data. For tax purposes, my fictional company must retain records of historical data. For this reason, I\'ve included a version c

相关标签:
7条回答
  • 2021-01-30 09:42

    I think you've started down the wrong path.

    Typically, for versioning or storing historical data you do one of two (or both) things.

    1. You have a separate table that mimics the original table + a date/time column for the date it was changed. Whenever a record is updated, you insert the existing contents into the history table just prior to the update.

    2. You have a separate warehouse database. In this case you can either version it just like in #1 above OR you simply snapshot it once every so often (hourly, daily, weekly..)

    Keeping your version number in the same table as your normal one has several problems. First, the table size is going to grow like crazy. This will put constant pressure on normal production queries.

    Second, it's going to radically increase your query complexity for joins etc in order to make sure the latest version of each record is being used.

    0 讨论(0)
提交回复
热议问题