[英]Auditing with ASP.NET and SQL Server
What is the best approach to audit the database for:审计数据库的最佳方法是什么:
My manager told me to add 3 extra columns to each table one for the ID
of whom updated the record, one for whom deleted the record and the third has a boolean value 0 for deleted and 1 for active (not deleted yet), but I think this is a work around and I'm pretty sure there is a better way to do it.我的经理告诉我在每个表中添加 3 个额外的列,一个用于更新记录的
ID
,一个用于删除记录的人,第三个具有 boolean 值 0 表示已删除,1 表示活动(尚未删除),但我认为这是一个解决方法,我很确定有更好的方法来做到这一点。
I was thinking of creating history tables and write an AFTER DELETE
trigger that saves all the DML.我正在考虑创建历史表并编写一个
AFTER DELETE
触发器来保存所有 DML。
Is this it or is there a more plain forward way?这是它还是有更简单的前进方式?
SQL Server 2016 onwards you can do this using Temporal tables : SQL Server 2016 之后,您可以使用临时表执行此操作:
A system-versioned temporal table is a type of user table designed to keep a full history of data changes, allowing easy point-in-time analysis.
系统版本时态表是一种用户表,旨在保留数据更改的完整历史记录,以便轻松进行时间点分析。 This type of temporal table is referred to as a system-versioned temporal table because the period of validity for each row is managed by the system (that is, the database engine).
这种类型的时态表称为系统版本时态表,因为每一行的有效期由系统(即数据库引擎)管理。
If what you are really trying to do is to record who changed what, a better approach is to use roles and groups to prevent users altering anything they shouldn't.如果您真正想要做的是记录谁更改了什么,更好的方法是使用角色和组来防止用户更改他们不应该更改的任何内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.