Generated banner for SQL Server Table Reconciliation
Generated logo for SQL Server Table Reconciliation

SQL Server Table Reconciliation

GitHubOfficialFirst committed by kapilsamantDistributed by GitHub

  • Skill
  • Review and audit
  • Data and AI
  • MIT
  • Low risk
  • Has scripts

From the author

Use when: comparing SQL Server tables across instances, data migration validation, ETL verification, row mismatch detection, schema drift, reconciliation report, production vs staging comparison. Uses mssql-python driver with Apache Arrow for fast columnar data transfer and comparison.
— the description by kapilsamant

AutoGineer summary

Written by AutoGineer from the skill’s own files, not by the author

This skill provides a structured procedure for comparing SQL Server tables between two different instances. It utilizes the mssql-python driver and Apache Arrow to extract and compare data, identifying missing rows, schema drift, and column mismatches. The process supports both individual table checks and wildcard patterns, producing a reconciliation report in console, CSV, or JSON formats.

What it does

  • Compares source and target SQL Server tables for data and schema consistency.
  • Detects missing rows, extra rows, and column-level mismatches.
  • Supports primary key auto-detection or manual specification for row identity.
  • Generates reconciliation reports in multiple formats including console, CSV, and JSON.
  • Implements hash-based pre-checks to optimize comparisons for large datasets.
  • Handles data normalization for types, strings, and timestamps during comparison.

When to use it

  • Validating data migrations between SQL Server environments.
  • Verifying ETL processes to ensure target data matches source data.
  • Detecting schema drift between production and staging databases.
  • Performing row-level mismatch detection across different database instances.

Advantages

  • Uses Apache Arrow for columnar data transfer.
  • Provides flexible output options for integration with other tools.
  • Includes logic for handling large tables via chunking and hash-based pre-checks.
  • Supports both SQL authentication and Azure AD (Entra) authentication.

Usage examples

“Compare the dbo.Orders table between my production and staging SQL Server instances.”
The agent executes the reconciliation script to compare the specified table, identifying any row mismatches or schema differences and printing the results to the console.
“Run a reconciliation for all tables in the dbo schema using Azure AD authentication and save the output to a CSV file.”
The agent triggers the script with the wildcard table specification, Entra authentication, and CSV output flag to generate a report of all tables in the schema.

Install

  1. Download the skill as a ZIP:

    https://mp-staging.autogineer.com/agent-skills/github/sql-server-table-reconciliation/download
  2. Unzip it into the cross-client skills folder of your project:

    mkdir -p .agents/skills && unzip sql-server-table-reconciliation.zip -d .agents/skills

Documentation by kapilsamant

SQL Server Table Reconciliation

Compare identical tables across two SQL Server instances using Python with mssql-python driver and Apache Arrow. Detect missing rows, column mismatches, schema drift, and produce a reconciliation report.

Workflow

  1. Collect connection details for source and target

  2. Identify primary key / composite key

  3. Detect schema differences

  4. Extract data via Arrow for efficient columnar transfer

  5. Compare rows and columns

  6. Generate reconciliation report

Collect Inputs

ParameterRequiredDescription
Source serverYesSource SQL Server (e.g. prod-server.database.windows.net)
Source databaseYesSource database name
Target serverYesTarget SQL Server (e.g. staging-server.database.windows.net)
Target databaseYesTarget database name
TablesYesComma-separated schema.table names, or schema.* wildcard (e.g. dbo.Orders,dbo.Items or dbo.*)
Auth modeYessql (user/password) or entra (Azure AD/token)
Primary keyAuto-detectColumn(s) forming the row identity. Auto-detect from metadata if not provided.
Columns to compareAllSubset of columns, or all non-PK columns
Chunk size100000Rows per batch for large tables
Output formatconsoleconsole, csv, parquet, or json

Bundled Script

The reconciliation logic is provided as a standalone script at scripts/reconcile.py. Invoke it with the appropriate arguments based on user inputs:

python scripts/reconcile.py \
    --source-server <source_server> \
    --source-database <source_database> \
    --target-server <target_server> \
    --target-database <target_database> \
    --tables "<table_spec>" \
    --auth <sql|entra> \
    --chunk-size <chunk_size> \
    --output <console|csv|json>
Optional arguments
ArgumentDescription
--primary-keyComma-separated PK column(s). Omit to auto-detect.
--columnsComma-separated columns to compare. Omit to compare all non-PK columns.
Example invocations

Single table with SQL auth:

python scripts/reconcile.py \
    --source-server prod-server.database.windows.net \
    --source-database ProdDB \
    --target-server staging-server.database.windows.net \
    --target-database StagingDB \
    --tables "dbo.Orders" \
    --auth sql \
    --output console

Wildcard with Entra auth and CSV output:

python scripts/reconcile.py \
    --source-server prod-server.database.windows.net \
    --source-database ProdDB \
    --target-server staging-server.database.windows.net \
    --target-database StagingDB \
    --tables "dbo.*" \
    --auth entra \
    --output csv
Prerequisites

Install required packages before running:

pip install mssql-python pyarrow pandas

Comparison Rules

  • Normalize types before comparing: cast decimals to same precision, trim strings, normalize datetime to UTC

  • NULL handling: NULL == NULL is considered a match (both sides missing = no diff)

  • Ignore row order: always compare by PK join, never positional

  • Large tables: chunk extraction with OFFSET/FETCH or ROW_NUMBER() partitioning

Hash-Based Optimization (for large tables)

When table has >1M rows, generate a hash pre-check:

SELECT {pk_cols},
       HASHBYTES('SHA2_256', CONCAT_WS('|', col1, col2, ...)) AS row_hash
FROM {table}

Compare hashes first; only fetch full rows for mismatched hashes. This reduces data transfer significantly.

Report Format

Reconciling dbo.EMPLOYEES...
Reconciling dbo.DEPARTMENTS...
Reconciling dbo.JOBS...

--- dbo.EMPLOYEES ---
  Source: 107  Target: 107
  Missing: 0  Extra: 0  Mismatches: 0
  Result: ✓ IDENTICAL

--- dbo.DEPARTMENTS ---
  Source: 27  Target: 27
  Missing: 0  Extra: 0  Mismatches: 3
  Result: ✗ DIFFERENCES FOUND

--- dbo.JOBS ---
  Source: 19  Target: 19
  Missing: 0  Extra: 0  Mismatches: 0
  Result: ✓ IDENTICAL

=== Summary: 2 passed, 1 failed, 0 skipped / 3 tables ===

When a single table is provided, include full detail (schema drift, sample rows, mismatches). When multiple tables, use the compact per-table format above with full detail only for tables with FAIL status.

Performance Considerations

ScenarioStrategy
< 100K rowsSingle Arrow fetch, in-memory pandas compare
100K–1M rowsChunked extraction (100K batches), streaming comparison
> 1M rowsHash pre-check → only fetch mismatched rows
Wide tables (100+ cols)Compare PK + hash first, drill into specific columns on mismatch
Network-constrainedUse Arrow columnar format (10-50x smaller than row-by-row)

Constraints

  • Always use mssql-python driver (not pyodbc, pymssql)

  • Always use Apache Arrow via cursor (cursor.arrow()) for data extraction

  • Connection MUST use connection string format, not keyword arguments (kwargs like encrypt=True throw errors)

  • Never compare without identifying PK first — ask user if auto-detect fails

  • Handle connection failures gracefully with retry logic

  • Never hardcode credentials in generated scripts — use os.environ / getpass (env vars: MSSQL_USER, MSSQL_PASSWORD)

  • Do not print credentials in output or logs

  • Use parameterized queries (? placeholders) for metadata lookups — never f-string interpolate user input into SQL

Files

ATTRIBUTION.md

Attribution

This folder is an unmodified copy of the Agent Skill "sql-server-table-reconciliation", distributed by AutoGineer (https://autogineer.com/agent-skills).

The skill's own files are unmodified copies. AutoGineer is not affiliated with or endorsed by the author or the publisher.

Files added by AutoGineer

  • ATTRIBUTION.md: this file, written by AutoGineer

  • LICENSE: copied from LICENSE

Requirements and compatibility

Written for: GitHub Copilot

Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta

“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.

Needs: Needs Python

Security

What our scanner noticed· Low risk

  • Instructions that use the network
  • Scripts that your agent may run

This skill includes scripts that your agent may run. Read them before you use it.

A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.

Attribution and licence

First committed by
GitHub avatar of kapilsamantkapilsamant
Publisher
GitHub (Official)
Distributed by
GitHub
Source
github/awesome-copilot · skills/sql-server-table-reconciliation · commit 797337f
Licence
MIT License (redistribution allowed)
  • LICENSE (added by AutoGineer from LICENSE)
  • ATTRIBUTION.md (written by AutoGineer)
Synced
Contributors
kapilsamant

AutoGineer is not affiliated with or endorsed by kapilsamant or GitHub.

Download ZIP

The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download sql-server-table-reconciliation.zip