SQL: retrieve only the records whose value has changed

后端 未结 7 1454
一整个雨季
一整个雨季 2020-12-17 02:13

Sorry for the nondescript title. I\'ll edit as we go along.

I have a table RateTable:

| Code   |  Date     |   Rate  |

  B001     2009-         


        
7条回答
  •  孤城傲影
    2020-12-17 02:27

    how about this approach guys?

    add a bit column named ChangedSinceLastRead, set it to 1 whenever you change the value in this table and in your select query read "SELECT * FROM Rate WHERE ChangedSinceLastRead = 1"

    after this select query fire another query "UPDATE Rate SET ChangedSinceLastRead = 0"

    although you have to fire 1 additional update query on this, you dont have to compute against dates in your select and your table storage takes less space (as bit is smaller to datetime)

    just another way to solve this ;-) i would love to see the performance implications of this as well as the above suggested datetime approach

提交回复
热议问题