Versioning in SQL Tables - how to handle it?

前端 未结 7 1299
囚心锁ツ
囚心锁ツ 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:35

    Idea 3 will work:

    SELECT * FROM EMPLOYEE AS e1
    WHERE Position = 'Coder'
    AND Version = (
        SELECT MAX(Version) FROM Employee AS e2
        WHERE e1.ID=e2.ID)
    

    You really want to use something like a date though, which is much easier to program and track, and will use the same logic (something like an EffectiveDate column)

    EDIT:

    Chris is totally correct about moving this info out of your production table for performance, especially if you expect frequent updates. Another option would be to make a VIEW that only shows you the most recent version of each person's info, that you build off of this table.

提交回复
热议问题