简体   繁体   English

跟踪更改/更新数据库表中的行的用户-SQL Server

[英]Track the user that changed/updated a row in database table - sql server

I need to make a column that whenever a user on the network updates the row through the listview in an ASP.net web page, it can find and store that in the column one that row. 我需要创建一列,每当网络上的用户通过ASP.net网页中的listview更新该行时,它都可以找到该行并将其存储在该行的第一列中。 Does anybody have an example of this? 有人有这样的例子吗?

One way you could do this, is to use SQL Change Tracking. 您可以执行此操作的一种方法是使用SQL更改跟踪。 Take a look at MSDN SQL Change Tracking 看一下MSDN SQL更改跟踪

Here is an excerpt to describe what the change tracking is capable of; 这是摘录,描述了变更跟踪的功能;

What rows have changed for a user table? 用户表的哪些行已更改? Only the fact that a row has changed is required, not how many times the row has changed or the values of any intermediate changes. 仅需要更改行这一事实,而不需要更改行多少次或任何中间更改的值。 The latest data can be obtained directly from the table that is being tracked. 可以直接从正在跟踪的表中获取最新数据。 Has a row changed?b The fact that a row has changed and information about the change must be available and recorded at the time that the change was made in the same transaction. 行是否已更改?b在同一事务中进行更改时,行已更改并且必须提供并记录有关更改的信息。

To enable this on SQL Server 2014 you need to run the following snippet; 要在SQL Server 2014上启用此功能,您需要运行以下代码段;

ALTER DATABASE AdventureWorks2012
SET CHANGE_TRACKING = ON
(CHANGE_RETENTION = 2 DAYS, AUTO_CLEANUP = ON)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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