Log changes to database table with trigger

前端 未结 12 2301
醉梦人生
醉梦人生 2021-02-08 18:48

I am looking for a good way to log changes that occur on a particular set of tables in my SQL Server 2005 database. I believe the best way to do this is through a trigger that g

12条回答
  •  死守一世寂寞
    2021-02-08 19:28

    Try installing some trigger based third party tool such as ApexSQL Audit and then reverse engineering how they do it. Just install it in trial mode and see how it generates triggers for capturing all different sorts of information.

    Several other things to consider are:

    Storage planning – if you have a lot of updates that means you’ll have a ton of audit data. I’d consider storing that data in separate databases. Especially if you plan on auditing more than one database.

    Managing the amount of data – over time you probably won’t be in a need to keep some very old records. Plan on easy deletion of old data

    Schema changes – what if schema is updated. In worst case your triggers will stop working and throw an error if not created correctly. At best case you’ll miss some of the data. This is also something to consider.

    Taking all of this into account it is probably the most time effective to go with some already developed solution vs creating this from scratch yourself.

提交回复
热议问题