SQL Server Change Data Capture - 捕获进行更改的用户

SQL Server Change Data Capture - Capture user who made the change(SQL Server Change Data Capture - 捕获进行更改的用户)
本文介绍了SQL Server Change Data Capture - 捕获进行更改的用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于SQL Server 更改数据捕获,您能否跟踪对行/列数据进行更改的用户,或者是否可以扩展 CDC 以允许这样做?我在文档中看不到任何内容.

Concerning SQL Server Change Data Capture, can you track the User who has made the change to the row/column data or is there anyway to extend CDC to allow this? I couldn't see anything in the documentation.

推荐答案

您无法使用 CDC 获取用户名..

You can't capture username with CDC..

您必须使用审计来执行此操作,或者如果这是一次性请求,您可以查询 TLOG..

You have to use Auditing to do so or if this is a one time request,you can query TLOG..

下面是请求相同的连接项..

Below is the connect item requesting the same..

CDC :用于捕获更多数据(用户名、日期/时间等)的选项

您也可以按照本文使用触发器玩卡特迈的疾病预防控制中心来自 Aaron Bertrand..

You also can use triggers as per this article Playing with CDC in Katmai from Aaron Bertrand..

创建表格:

CREATE TABLE cdc.dbo_test_CT_MoreInfo
(
startlsn BINARY(10),
seqval BINARY(10),
operation INT,
username SYSNAME NOT NULL DEFAULT SUSER_SNAME(),
eventDate DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (startlsn, seqval, operation)
);
GO

创建触发器:

CREATE TRIGGER cdc.LogMoreCDCInfo
ON cdc.dbo_test_CT
FOR INSERT
AS
BEGIN
  IF @@ROWCOUNT > 0
  BEGIN
    INSERT cdc.dbo_test_CT_MoreInfo(startlsn,seqval,operation)
      SELECT __$start_lsn, __$seqval, __$operation FROM inserted;
  END
END
GO

这篇关于SQL Server Change Data Capture - 捕获进行更改的用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
SSIS: Model design issue causing duplications - can two fact tables be connected?(SSIS:模型设计问题导致重复-两个事实表可以连接吗?)
SQL Server Graph Database - shortest path using multiple edge types(SQL Server图形数据库-使用多种边类型的最短路径)
Invalid column name when using EF Core filtered includes(使用EF核心过滤包括时无效的列名)
How should make faster SQL Server filtering procedure with many parameters(如何让多参数的SQL Server过滤程序更快)
How can I generate an entity–relationship (ER) diagram of a database using Microsoft SQL Server Management Studio?(如何使用Microsoft SQL Server Management Studio生成数据库的实体关系(ER)图?)