Pular para o conteúdo

Esta página ainda não está disponível em português (Brasil), por isso é exibida em inglês.

SQL Data Synchronisation Guide

An overview of the main ways to synchronise data between SQL Server databases, from full reloads and watermarks to Change Tracking, CDC and replication, and how to choose between them.

Keeping data in step between two SQL Server databases is one of the most common jobs in database operations. A reporting copy needs refreshing from production. A migration needs the new system to catch up with the old one before cutover. A test environment needs current reference data. A downstream system needs changes as they happen.

There is no single right way to do it. The best approach depends on how much data there is, how current the copy needs to be, whether you need deletes, and how much load the source can take. This guide is an overview of the main options and how to choose between them.

The main approaches

| Approach | How it works | Good for |

| --- | --- | --- |

| Full reload | Empty the target and copy everything again | Small tables, simple needs, occasional refreshes |

| Watermark (incremental) | Copy rows changed since the last run, based on a column such as a modified date or rowversion | Large tables where rows are mostly inserted or updated |

| Change Tracking | SQL Server records which rows changed, by key, since a version number | Incremental sync including deletes, with low overhead |

| Change Data Capture (CDC) | SQL Server reads the transaction log and records every change with before and after values | Auditing, data pipelines and full change history |

| Transactional replication | SQL Server pushes changes to subscribers continuously | Near real-time copies of whole tables |

| Compare and merge | Compare source and target rows by key and apply the differences | Repairing drift and one-off alignment |

Full reload

The simplest option is often the right one. If a table is small, or the refresh only happens weekly, truncating the target and copying everything again is easy to build, easy to understand and always correct. The downsides are time and load: it copies every row every time, and the target is empty or incomplete while it runs, unless you load into a staging table and switch it in.

Incremental sync with a watermark

For larger tables, copy only what has changed. A watermark is a column that tells you which rows are new or changed since the last run, typically a modified date or a `rowversion` column. Each run copies rows above the last watermark and then records the new high point. It is efficient and widely used, but it has two classic weaknesses: it can't see deletes, and a badly chosen watermark can miss rows. Our guide to [incremental synchronisation using watermarks](/guides/incremental-sql-table-synchronisation-using-watermarks) covers both in detail.

Change Tracking

Change Tracking is built into SQL Server and is designed for exactly this kind of sync. Once enabled on a database and table, SQL Server records the primary key of every row that is inserted, updated or deleted, with a version number. A sync process asks for "everything changed since version N" and gets back the keys and the type of change, including deletes:

```sql

ALTER DATABASE SalesDb SET CHANGE_TRACKING = ON (CHANGE_RETENTION = 3 DAYS, AUTO_CLEANUP = ON);

ALTER TABLE dbo.Orders ENABLE CHANGE_TRACKING;

DECLARE @last_sync bigint = 1500;

SELECT ct.SYS_CHANGE_OPERATION, ct.OrderId, o.*

FROM CHANGETABLE(CHANGES dbo.Orders, @last_sync) ct

LEFT JOIN dbo.Orders o ON o.OrderId = ct.OrderId;

SELECT CHANGE_TRACKING_CURRENT_VERSION() AS next_sync_version;

```

It doesn't record the old values, only which rows changed, so the sync reads current values from the table. Make sure each sync runs well within the retention period, or changes will be cleaned up before you read them.

Change Data Capture

CDC reads the transaction log and writes every change, with the values before and after, into change tables. It is more detailed than Change Tracking, which makes it suitable for auditing and for feeding data pipelines that need every intermediate change, not just the latest state. It also has more overhead, needs SQL Server Agent jobs to run, and has more moving parts to manage.

Replication

Transactional replication continuously copies changes from a publisher to one or more subscribers, usually within seconds. It is mature and fast, but it is a significant piece of infrastructure to set up, monitor and troubleshoot. Our guide to [SQL Server replication versus table synchronisation](/guides/sql-server-replication-vs-table-synchronisation) compares the two.

Choosing an approach

A few questions narrow the choice quickly:

  • **How current does the copy need to be?** Seconds points to replication; minutes or hours opens up every option.
  • **Do deletes need to be synchronised?** If so, a simple watermark won't do; use Change Tracking, CDC, replication or a comparison.
  • **How big is the data and how much changes?** Small or mostly-changing tables suit full reloads; large, slowly changing ones suit incremental methods.
  • **Can you change the source?** Change Tracking, CDC and rowversion columns all need changes to the source database.
  • **How much complexity can you support?** Simpler methods are easier to run reliably for years.

Always verify the result

Whatever method you use, check that the target really matches. Row counts per table are a cheap first check. For important tables, compare totals or checksums on key columns, or sample rows by key. Sync processes can fail quietly, for example by skipping rows with unexpected values, and only verification catches that.

Troubleshooting Scenarios

The target has rows that were deleted from the source

The sync can't see deletes. Use Change Tracking, CDC or a periodic comparison by key to catch them.

The incremental sync misses some rows

The watermark column may not be updated on every change, or rows may be committed out of order. Use rowversion or a safety overlap window.

Change Tracking reports that changes are no longer available

The sync ran less often than the retention period. Increase retention or run the sync more often, and do a full reload to recover.

Sync runs are getting slower

More data is changing, or the watermark query is scanning. Check the index on the watermark column and the volume of changes per run.

Where SQL Cockpit fits

Synchronisation work needs a clear view of what is being moved, how it is configured and whether each run worked. SQL Cockpit includes table synchronisation workflows, with configuration, progress and outcomes visible in one workspace, alongside the database context of the source and target. The method you choose still depends on the questions in this guide.

FAQ

What are the main ways to synchronise SQL Server data?

Full reloads, watermark-based incremental copies, Change Tracking, Change Data Capture, replication and compare-and-merge.

What is the difference between Change Tracking and CDC?

Change Tracking records which rows changed; CDC records every change with before and after values. CDC is more detailed but has more overhead.

How do I synchronise deletes?

Use Change Tracking, CDC, replication or a periodic key comparison. A simple watermark can't see deleted rows.

When is a full reload the right choice?

For small tables or infrequent refreshes, where copying everything is quick and simplicity matters more than efficiency.

How do I check a sync worked?

Compare row counts, then totals or checksums on key columns, and sample rows by key for important tables.

Semantic Keywords

  • SQL data synchronisation guide
  • schema drift
  • table synchronisation
  • environment comparison
  • migration orchestration
  • SQL Server monitoring
  • SQL Agent monitoring
  • runtime analysis
  • runtime baselines
  • runtime variance
  • SQL Server operations
  • database telemetry
  • historical analysis
  • operational dashboards
  • cross-server monitoring

Suggested Related Articles