Chuyển đến nội dung
Skillpedia
Cơ sở dữ liệu40k · #7435

sql-server-table-reconciliation

Skill này làm gì

Công cụ này so sánh các bảng giống nhau giữa hai cơ sở dữ liệu SQL Server để tìm khác biệt. Nó kiểm tra các dòng bị thiếu, dữ liệu cột khác nhau hoặc thay đổi về cấu trúc bảng.

Khi nào nên dùng

  • ✓Kiểm tra dữ liệu sau khi di chuyển.
  • ✓So sánh môi trường thực tế (production) với môi trường thử nghiệm (staging).
  • ✓Đảm bảo các quy trình cập nhật dữ liệu tự động (ETL) hoạt động như mong đợi.

Liên kết skill

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

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/github/awesome-copilot/blob/main/skills/sql-server-table-reconciliation/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“So sánh các bảng “Customers” và “Orders” giữa máy chủ production và staging.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Bạn cung cấp thông tin kết nối cho cả hai cơ sở dữ liệu SQL Server và tên bảng. Công cụ trích xuất dữ liệu một cách hiệu quả và so sánh từng dòng dựa trên một mã định danh duy nhất.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

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

…

Câu hỏi thường gặp

Khóa chính (primary key) là gì?

Đây là một cột (hoặc tập hợp cột) xác định duy nhất từng dòng trong một bảng, giống như số định danh cá nhân của mỗi người hoặc mã đơn hàng trong một giao dịch bán.

Công cụ xử lý bảng rất lớn như thế nào?

Nó có thể xử lý bảng theo từng phần (lô), hoặc tạo mã băm (hash) cho mỗi dòng và so sánh các mã này trước, cách này nhanh hơn nhiều.

Điều gì xảy ra nếu dữ liệu khác nhau?

Công cụ tạo báo cáo cho biết dòng hoặc cột nào có khác biệt, hoặc dòng nào chỉ tồn tại trên một máy chủ mà không có trên máy chủ kia.

Chi tiết

Mô tả gốc của tác giả

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

Độ phổ biến

Sao GitHub
40k
Vị trí xếp hạng
#7435
Giấy phép
MIT
Cập nhật
15/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự