(+351) 21 24 10006  ·  info@bconcepts.pt
Carnaxide, Lisbon

How to Automate Data Provenance in Data Governance: step by step

João Barros 24 de November de 2026 4 min read

Automating Data Provenance in Data Governance allows consistently recording the origin, transformations and destination of data — essential for audits, trust and troubleshooting. This guide shows how to create an automated provenance capture process using triggers and ETL metadata.

Prerequisites

  • Account with administrator permissions on the storage system and the database (e.g.: Azure SQL, SQL Server).
  • Basic familiarity with SQL and the ETL/ELT process that moves data (e.g.: Azure Data Factory, SQL Jobs).
  • Area to store provenance metadata (an accessible Audit/Provenance table).
  • SQL editor or access to PowerShell/CLI to automate scheduling.

Step 1: Define the minimal Data Provenance model

Explain why: a simple model captures the essentials — who, when, source, transformation and version. It keeps the implementation practical and extensible.

CREATE TABLE DataProvenance (
  ProvenanceId INT IDENTITY(1,1) PRIMARY KEY,
  SourceSystem NVARCHAR(100) NOT NULL,
  SourceObject NVARCHAR(200) NOT NULL,
  TargetObject NVARCHAR(200) NOT NULL,
  OperationType NVARCHAR(50) NOT NULL, -- INSERT, UPDATE, DELETE, LOAD
  ChangedBy NVARCHAR(100),
  ChangeTime DATETIME2 DEFAULT SYSUTCDATETIME(),
  TransformDetails NVARCHAR(MAX), -- JSON ou texto com passos
  BatchId NVARCHAR(100) NULL
);

Step 2: Capture provenance during ETL/ELT loads

Explain why: the best point to record provenance is at the end of the ETL/ELT pipeline, where source, destination and applied transformations are known. Here I exemplify with a final INSERT that records metadata.

-- Exemplo: após carregar dados na tabela TargetTable
DECLARE @batchId NVARCHAR(100) = 'load_20261124_001';
INSERT INTO TargetTable (col1,col2)
SELECT col1,col2 FROM StagingTable;

INSERT INTO DataProvenance (SourceSystem, SourceObject, TargetObject, OperationType, ChangedBy, TransformDetails, BatchId)
VALUES ('SalesSystem','staging.SalesLoad','dbo.TargetTable','LOAD', SUSER_SNAME(),
  '{"steps": ["trim","map_customer_id","calc_amount"]}', @batchId);

Step 3: Automate logging from triggers (when applicable)

Explain why: for ad hoc or manual changes in the database, triggers ensure each critical operation is recorded. Use triggers carefully to avoid degrading performance; record only metadata.

CREATE TRIGGER trg_TargetTable_Audit
ON dbo.TargetTable
AFTER INSERT, UPDATE, DELETE
AS
BEGIN
  SET NOCOUNT ON;
  DECLARE @op NVARCHAR(10) = CASE WHEN EXISTS(SELECT 1 FROM inserted) AND EXISTS(SELECT 1 FROM deleted) THEN 'UPDATE'
                                   WHEN EXISTS(SELECT 1 FROM inserted) THEN 'INSERT'
                                   ELSE 'DELETE' END;

  INSERT INTO DataProvenance (SourceSystem, SourceObject, TargetObject, OperationType, ChangedBy, TransformDetails)
  VALUES ('database','client_app','dbo.TargetTable', @op, SUSER_SNAME(), 'trigger_capture');
END;

Step 4: Enrich provenance with pipeline metadata

Explain why: including pipeline metadata (execution ID, parameters, timestamps and duration) helps correlate failures and outcomes. If you use Azure Data Factory/ADF, pass parameters that step 2 records.

-- Exemplo mínimo de metadados extra gravados pós-pipeline
INSERT INTO DataProvenance (SourceSystem, SourceObject, TargetObject, OperationType, ChangedBy, TransformDetails, BatchId)
VALUES ('ADF','pipeline:CopySales','dbo.TargetTable','LOAD','adf-service',
  '{"pipelineRunId":"f3b2-...","durationSec":42,"rowsCopied":12345}', 'pipelineRun_f3b2');

Step 5: Automate retention and archiving of provenance

Explain why: provenance grows over time. Defining retention policies prevents unbounded growth, keeping data necessary for audits. Here a simple job moves provenances older than X days and archives them to a historical table.

-- Mover para tabela histórica e apagar
CREATE TABLE DataProvenance_History AS SELECT * FROM DataProvenance WHERE 1=0;

-- Job SQL (exemplo): mover e apagar entries com mais de 365 dias
WITH old AS (
  SELECT * FROM DataProvenance WHERE ChangeTime < DATEADD(day,-365, SYSUTCDATETIME())
)
INSERT INTO DataProvenance_History
SELECT * FROM old;

DELETE FROM DataProvenance WHERE ChangeTime < DATEADD(day,-365, SYSUTCDATETIME());

Verify the result

To confirm the automation works, run a test pipeline and check the DataProvenance table: there should be one row per significant operation with BatchId, OperationType and TransformDetails populated. Also verify triggers by creating, updating and deleting records in TargetTable and observing entries in the provenance table. Finally, simulate a retention job and confirm old entries were moved to DataProvenance_History.

Conclusion

Automating Data Provenance makes data origin and transformations traceable, improving auditability and trust. Next steps: link these records to a Metadata Catalog or to Microsoft Purview, validate performance and encrypt sensitive columns. Tip: start simple (minimal model) and only then add complexity such as file hashes or detailed lineage — which part do you want to implement first?