bloginfo

SQL Server : how to read the transaction log file

Nov 20th, 2018 (edited)
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 1.03 KB | None | 0 0
  1. -- Source : https://www.dsfc.net/infrastructure/base-de-donnees-infrastructure/sql-server-lire-journaux-des-transactions/
  2. WITH
  3.     BT AS
  4.     (
  5.         SELECT
  6.             [Begin Time] AS debut,
  7.             [Transaction Name] AS type,
  8.             Operation AS operation,
  9.             [Transaction ID] AS numtrans
  10.             --AllocUnitName,
  11.         FROM
  12.             sys.fn_dblog(NULL,NULL) AS BT
  13.         WHERE [Begin Time] IS NOT NULL
  14.     ),
  15.     ET AS
  16.     (
  17.         SELECT
  18.             Operation AS operation,
  19.             [End Time] AS fin,
  20.             [Transaction ID] AS numtrans
  21.         FROM
  22.             sys.fn_dblog(NULL,NULL)
  23.         WHERE
  24.             [End Time] IS NOT NULL
  25.     ),
  26.     A AS
  27.     (
  28.         SELECT
  29.             [Transaction ID] AS numtrans,
  30.             AllocUnitName AS objet
  31.         FROM
  32.             sys.fn_dblog(NULL,NULL)
  33.         WHERE
  34.             AllocUnitName IS NOT NULL
  35.     )
  36.     SELECT DISTINCT
  37.         BT.type,
  38.         BT.debut,
  39.         ET.fin,
  40.         BT.operation,
  41.         ET.operation,
  42.         A.objet
  43.     FROM
  44.         BT
  45.         INNER JOIN ET ON BT.numtrans=ET.numtrans
  46.         INNER JOIN A ON ET.numtrans=A.numtrans
  47. WHERE
  48.     ET.operation != 'LOP_ABORT_XACT'
  49. AND
  50.     BT.type IN ('UPDATE','DELETE','TRUNCATE TABLE','INSERT')
  51. ORDER BY
  52.     debut,fin;
  53. GO
Add Comment
Please, Sign In to add comment