简体   繁体   English

使用 ASP.NET 和 SQL 服务器进行审计

[英]Auditing with ASP.NET and SQL Server

What is the best approach to audit the database for:审计数据库的最佳方法是什么:

  1. Make a copy of the deleted and updated records.复制已删除和更新的记录。
  2. Save the date and user ID of the ones who did the DML which is (the ID) was saved on a session in ASP.NET保存执行 DML 的人的日期和用户 ID,即(ID)保存在 ASP.NET 中的 session

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM