What is the best implementation for DB Audit Trail? [closed]

廉价感情. 提交于 2019-12-12 16:47:36

问题


A DB Audit Trail captures the User Last Modified, Modified Date, and Created Date.

There are several possible implementations:

  • SQL Server Triggers
  • Add UserModified, ModifiedDate, CreatedDate columns to the database and include logic in Stored Procedures or Insert, Update statements accordingly.

It would be nice if you include implementation (or link to) in your answer.


回答1:


Depending on what you're doing, you might want to move the audit out of the data layer into the data access layer. It give you more control.

I asked a similar question wrt NHibernate and SqlServer here.




回答2:


I totally second @IainMH (and voted him up).

You want to have it in your DAL and ideally tied to some kind of aspect/interceptor/code injection mechanism.




回答3:


+2 for implementation of when/how to audit in the DAL.

As for where the audit entries themselves should live, it depends on how it will be visible. I'd do a separate table if users can view a separate "audit trail report," but tag existing tables if you want to display last modified-type audits inline.




回答4:


Here is the implementation I use to audit tables: Pop Rivett's SQL Server FAQ No.5: Pop on the Audit Trail



来源:https://stackoverflow.com/questions/60920/what-is-the-best-implementation-for-db-audit-trail

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!