Tracking changes in a SQL server 2005 database

前端 未结 8 1564
既然无缘
既然无缘 2020-12-29 00:05

I have been tasked with developing a solution that tracks changes to a database.

For updates I need to capture:

  • date of update
  • old value
8条回答
  •  北荒
    北荒 (楼主)
    2020-12-29 00:33

    First off, in all your tables you should have at least these columns added to the data columns DateCreated, UserCreated, DateModified, UserModified. Possibly you might want to add a "Status" or "LastAction" column so that you don't ever actually delete a row you just set it to a deleted/inserted/updated status. Next you could create a "History table" which is an exact copy of the first table. Then on any updates or deletes have the trigger copy the Deleted table entries into the History table changing the DateModified, UserModified, and Status fields at the same time.

提交回复
热议问题