SQL Server Table Reconciliation
GitHubOfficialFirst committed by kapilsamantDistributed by GitHub
- Skill
- Review and audit
- Data and AI
- MIT
- Low risk
- Has scripts
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
Download the skill as a ZIP:
https://autogineer.com/agent-skills/github/sql-server-table-reconciliation/downloadUnzip 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
Collect connection details for source and target
Identify primary key / composite key
Detect schema differences
Extract data via Arrow for efficient columnar transfer
Compare rows and columns
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 consoleWildcard 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 csvPrerequisites
Install required packages before running:
pip install mssql-python pyarrow pandasComparison Rules
Normalize types before comparing: cast decimals to same precision, trim strings, normalize datetime to UTC
NULL handling:
NULL == NULLis considered a match (both sides missing = no diff)Ignore row order: always compare by PK join, never positional
Large tables: chunk extraction with
OFFSET/FETCHorROW_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 |
| 100K–1M rows | Chunked extraction (100K batches), streaming comparison |
| > 1M rows | Hash pre-check → only fetch mismatched rows |
| Wide tables (100+ cols) | Compare PK + hash first, drill into specific columns on mismatch |
| Network-constrained | Use Arrow columnar format (10-50x smaller than row-by-row) |
Constraints
Always use
mssql-pythondriver (not pyodbc, pymssql)Always use Apache Arrow via cursor (
cursor.arrow()) for data extractionConnection MUST use connection string format, not keyword arguments (kwargs like
encrypt=Truethrow 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.mdAdded by AutoGineer901 B
- LICENSELicence file added by AutoGineer1.0 KiB
- SKILL.md5.7 KiB
- scripts/reconcile.pyScript12.9 KiB
LICENSE
MIT License Copyright GitHub, Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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
kapilsamant
- 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