Skip to content
Skillpedia
Databases40k · #5378

sql-server-table-reconciliation

Compares SQL Server tables across different locations to validate data. It's useful for migrations, ETL checks, and detecting discrepancies.

What it does

This tool compares identical tables across two SQL Server databases to find differences. It checks for missing rows, differing column data, or changes in table structure.

When to use it

  • ✓Validating data after a migration.
  • ✓Comparing a production environment with a staging environment.
  • ✓Ensuring automated data update processes (ETL) worked as expected.

Example of what to ask your AI

“Compare the 'Customers' and 'Orders' tables between the production and staging servers.”

Want more? Open the sections below.

How to use

The easiest way: copy the message below and paste it into Claude, ChatGPT, Cursor or any AI. It reads the skill and follows the instructions.

Skill link

https://github.com/github/awesome-copilot/blob/main/skills/sql-server-table-reconciliation/SKILL.md

Ready-to-paste message

Use this skill to help me: https://github.com/github/awesome-copilot/blob/main/skills/sql-server-table-reconciliation/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
How it works

You provide the connection details for both SQL Server databases and the table names. The tool efficiently extracts the data and compares it row by row, based on a unique identifier.

Installation

Easiest way: copy the skill link and paste it into Claude, ChatGPT or Cursor asking it to follow the instructions.

In the terminal (Claude Code, Codex, Cursor), in your project folder:

npx skills add github/awesome-copilot --skill sql-server-table-reconciliation

Or download just the file:

curl -L https://raw.githubusercontent.com/github/awesome-copilot/main/skills/sql-server-table-reconciliation/SKILL.md -o SKILL.md
Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

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

Parameter Required Description
Source server Yes Source SQL Server (e.g. prod-server.database.windows.net)
Source database Yes Source database name
Target server Yes Target SQL Server (e.g. staging-server.database.windows.net)
Target database Yes Target database name
Tables Yes Comma-separated schema.table names, or schema.* wildcard (e.g. dbo.Orders,dbo.Items or dbo.*)
Auth mode Yes sql (user/password) or entra (Azure AD/token)
Primary key Auto-detect Column(s) forming the row identity. Auto-detect from metadata if not provided.
Columns to compare All Subset of columns, or all non-PK columns
Chunk size 100000 Rows per batch for large tables
Output format console console, 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

Argument Description
--primary-key Comma-separated PK column(s). Omit to auto-detect.
--columns Comma-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

Scenario Strategy
< 100K rows Single Arrow fetch, in-memory pandas compare

…

FAQ

What is a primary key?

It's a column (or set of columns) that uniquely identifies each row in a table, like a social security number for people or an order ID for sales.

How does the tool handle very large tables?

It can process tables in chunks (batches) or generate a summary code (hash) for each row and compare these codes first, which is much faster.

What happens if data is different?

The tool generates a report showing which rows or columns have differences, or which rows exist on one server but not the other.

Details

Original description by 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.

repo: github/awesome-copilot

Popularity

GitHub stars
40k
Ranking position
#5378
License
MIT
Updated
10/15/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills