SQL Server のトランザクション ログ ファイルからユーザーを取得するにはどうすればよいですか?
このクエリを試しましたが、適切なユーザーが得られません
SELECT
CASE
WHEN (SELECT NAME
FROM SYS.SERVER_PRINCIPALS lgn
WHERE Rtrim(lgn.SID) = Rtrim(log2.[TRANSACTION SID])) IS NOT
NULL THEN
'login: '
+ Upper((SELECT NAME FROM SYS.SERVER_PRINCIPALS lgn WHERE Rtrim(lgn.SID)
= Rtrim
(log2.[TRANSACTION SID])))
ELSE 'db user: '
+ Upper((SELECT NAME FROM SYS.SERVER_PRINCIPALS lgn WHERE Rtrim(
lgn.SID)
= Rtrim(log2.[TRANSACTION SID] )))
END
AS 'Login_or_User',
log1.*,
CASE log1.__$OPERATION
WHEN 1 THEN 'DELETE'
WHEN 2 THEN 'INSERT'
WHEN 4 THEN 'UPDATED VALUE'
WHEN 3 THEN 'PREVIOUS UPDATED VALUE'
ELSE NULL
END
AS operation,
CONVERT(VARCHAR(19), log2.[BEGIN TIME]) AS 'Begin Time',
LEFT(log.ALLOCUNITNAME, Charindex('.', log.ALLOCUNITNAME) - 1)
AS 'Schema',
LEFT(RIGHT(log.ALLOCUNITNAME, Len(log.ALLOCUNITNAME) -
Charindex('.', log.ALLOCUNITNAME)),
Charindex('.', RIGHT(log.ALLOCUNITNAME,
Len(log.ALLOCUNITNAME)
-
Charindex('.', log.ALLOCUNITNAME))) - 1) AS 'Object',
SYS.Fn_cdc_hexstrtobin(Substring(log.[CURRENT LSN], 1, 8)
+ Substring(log.[CURRENT LSN], 10, 8)
+
Substring(log.[CURRENT LSN], 19, 4)) currentlsn
FROM DBO.TEMPTABLE log1
LEFT JOIN ::FN_DBLOG(NULL, NULL) log
ON log1.__$SEQVAL = SYS.Fn_cdc_hexstrtobin(
Substring(log.[CURRENT LSN], 1, 8)
+ Substring(log.[CURRENT LSN], 10, 8)
+ Substring(log.[CURRENT LSN], 19, 4))
LEFT JOIN ::FN_DBLOG(NULL, NULL)log2
ON log.[TRANSACTION ID] = log2.[TRANSACTION ID]
LEFT JOIN SYS.ALLOCATION_UNITS au
ON log.ALLOCUNITID = au.ALLOCATION_UNIT_ID
LEFT JOIN SYS.PARTITIONS p
ON p.PARTITION_ID = au.CONTAINER_ID
LEFT JOIN SYS.OBJECTS so
ON so.OBJECT_ID = p.OBJECT_ID
LEFT JOIN SYS.SERVER_PRINCIPALS spa
ON spa.SID = log2.[TRANSACTION ID]
CDC(CHange Data Capture)が有効になっているデータベースをチェックするためのこのコードは、特定のテーブルを選択して変更を取得します