After a SQL Server migration, matching row counts are a useful first check. They tell you that two tables contain the same number of rows. They do not tell you whether those rows contain the same values, or whether the destination contains the same primary keys. One missing row and one extra row can leave the total unchanged.
Smaller differences can also survive a count check: an accent removed from a name, a decimal changed from 12.50 to 12.51, or a NULL converted to empty text. The row still exists, but its content has changed. A useful acceptance report needs to distinguish missing rows, extra rows, and rows whose values differ under the same key.
Compare rows by their complete primary keys
The verifier described here is a small .NET 8 command-line tool for comparing selected tables between two SQL Server databases. It reads COUNT_BIG(*) and asks SQL Server to calculate a SHA-256 hash for each row. Rows are matched using their complete primary keys, including composite keys.
The primary key identifies the row; the row hash represents its serialized column values. The implementation retains full serialized key bytes rather than reducing primary keys to hashes. A changed primary-key value therefore appears as a missing row and an extra row.
Here is the changed-row branch from its Verifier.cs, reached when the target contains the same serialized primary key:
else if (!entry.Value.Hash.AsSpan().SequenceEqual(targetRow.Hash))
{
changed++;
if (changedKeys.Count < 20) changedKeys.Add(entry.Value.DisplayKey);
}
Every difference contributes to the total. The report includes up to 20 example keys per category and table, so a short example list does not mean the remaining differences were ignored.
Serialization matters here. Each column contributes a frame that distinguishes NULL from a non-NULL value and includes the payload length. Empty text consequently differs from NULL, and framing avoids ambiguity when multiple values are combined. SQL Server runs HASHBYTES('SHA2_256', ...) over the framed row.
Before comparing row hashes, the tool checks column and primary-key definitions. A definition mismatch produces a schema-difference result, with row comparison categories marked unavailable. It does not silently treat incompatible tables as successfully compared.
What the report looks like
The following example is synthetic, invented for this article. It is not output from a customer database or one of the recorded validation runs.
Result: DIFFERENCES — one or more selected tables differ.
| Table | Source rows | Target rows | Missing | Extra | Changed | Result |
| --- | ---: | ---: | ---: | ---: | ---: | --- |
| dbo.CustomerContacts | 300 | 300 | 1 | 1 | 2 | DIFFERENCES |
Missing keys — showing 1 of 1
- {"AccountId":"10","ContactId":"2"}
Extra keys — showing 1 of 1
- {"AccountId":"10","ContactId":"99"}
Changed keys — showing 2 of 2
- {"AccountId":"10","ContactId":"1"}
- {"AccountId":"10","ContactId":"3"}
Both sides contain 300 rows, yet the destination is missing one source key, contains another key absent from the source, and has two rows with different hashes. The changed-key list identifies rows to investigate; it does not provide a column-by-column value diff.
The application prints a Markdown report and writes migration-report.md. Exit code 0 means every selected table matches, 1 indicates differences, and 2 indicates an invalid invocation or incomplete verification. An incomplete run must not be interpreted as a successful comparison.
What was actually validated
The tool's validation record lists a Windows run on October 27, 2026, against a temporary SQL Server 2025 LocalDB instance. The Release build targeting .NET 8 completed with zero warnings and zero errors. All six recorded checks passed:
- Equal tables returned exit code 0 and MATCH for both tables.
- A missing contact with composite key AccountId 10, ContactId 2 was detected.
- Changing NULL to empty text was reported as a changed row.
- An extra contact with composite key AccountId 10, ContactId 99 was detected.
- Removing an accent from Unicode text and changing 12.50 to 12.51 produced two changed keys.
- A 20,000-row table with one changed amount identified OrderId 15000 in about one second.
That timing is an observation from that LocalDB environment, not a performance guarantee. These are the recorded validation results; the tool was not rebuilt or rerun to prepare this article. After publishing it, the first four cases were run again on November 18, 2026, with the same results.
The source code, the example databases and the four reports from that run are public: https://github.com/martinPisacreta/sqlserver-migration-verifier
Limits to agree before verification
Very large tables, databases on different servers, and types outside the documented supported list were not covered by those checks. The tool scans both tables and holds key/hash dictionaries in memory. Memory use grows with row count and key size; there is no batching or resume mechanism.
Both databases require snapshot isolation. Their snapshots are independent, so writes should be paused before acceptance. SHA-256 equality provides probabilistic evidence about the selected rows. It does not validate omitted tables, foreign keys, indexes, stored procedures, permissions, or application behavior.
A fixed-scope verification
I offer a fixed-scope SQL Server migration verification using copies or databases restored from backups.
We agree on the selected tables, supported types, and comparison conditions before starting.
The deliverable is a report of missing, extra, and changed rows by table, with example primary keys and explicit limitations.
You can hire me through Upwork: https://www.upwork.com/freelancers/~014a89dccd8bf740d0
Top comments (0)