Copy job with CDC in Fabric: updates and deletes too

A Fabric Copy job reads a CDC-enabled source and applies inserts, updates and deletes to the destination, as a Merge or as SCD Type 2 history. When to pick it over a watermark.

Short answer: turn on change data capture on the source tables, create a Copy job with incremental copy, and it picks CDC on its own for those tables. Each run then copies only the rows that changed, deletes included, and writes them either as a Merge (the destination mirrors the source) or as SCD Type 2 (every old version kept, with Valid_From, Valid_To and Is_Current). A watermark column can do inserts and updates, but never sees a delete.

Most incremental loads compare a modified_at column with the last run. That works until a row is deleted at the source: it has no new timestamp, so it stays in the lakehouse forever and the report counts a customer who is gone. CDC reads the database's own change log instead, so the delete arrives like any other change.

CDC or a watermark?

Watermark
  • compares a column (datetime, date, integer, ROWVERSION) with the last run
  • inserts and updates
  • no setup on the source
CDC
  • reads the source's change log
  • inserts, updates and deletes
  • CDC turned on at the source
  • needed for SCD Type 2
Two ways a Copy job finds changes

The Copy job finds the CDC-enabled tables itself. One catch: if a single job mixes tables with CDC and tables without, it treats all of them as watermark copies. Keep the CDC tables in a job of their own.

What happens to the rows?

A customers table in Azure SQL has three rows at the first run, which copies everything. Before the second run, three things happen at the source:

customer_idcity at run 1changecity at run 2
C-101ViennanoneVienna
C-102GrazupdatedSalzburg
C-103Linzdeleted(gone)
C-104(new)insertedInnsbruck
Changes between run 1 and run 2

With Merge, the default for CDC, the destination is the source again: three rows.

customer_idcity
C-101Vienna
C-102Salzburg
C-104Innsbruck
Destination after run 2, Merge (SCD Type 1)

With SCD Type 2, the old version of C-102 is closed, the deleted C-103 is closed instead of removed, and the new rows are current. Five rows, of which three are current, the same three as the Merge:

customer_idcityValid_FromValid_ToIs_Current
C-101Viennarun 1NULLtrue
C-102Grazrun 1run 2false
C-102Salzburgrun 2NULLtrue
C-103Linzrun 1run 2false
C-104Innsbruckrun 2NULLtrue
Destination after run 2, SCD Type 2

A report that wants today's picture filters Is_Current = true; one that wants "where did this customer live in March" joins on the dates. A watermark copy of the same changes would have three rows plus C-103 still sitting in Linz.

How do you set it up?

  1. 1
    Enable CDCon the database and each table, at the source
  2. 2
    Copy jobincremental copy; the CDC tables are found
  3. 3
    Write methodMerge, or SCD Type 2 for history
  4. 4
    Scheduleone or several schedules in the job
From a source table to a Fabric destination

On SQL Server or Azure SQL, CDC is two procedures, run once by someone with the rights:

EXEC sys.sp_cdc_enable_db;

EXEC sys.sp_cdc_enable_table
  @source_schema = N'dbo',
  @source_name   = N'customers',
  @role_name     = NULL;

Then in Fabric: New item, Copy job, pick the connection and the tables, choose Incremental copy, and on the write settings pick Merge or SCD Type 2. Both use the primary key by default. If a run fails, the next one starts from the end of the last successful run, so nothing is lost; you can also reset one table back to a full copy.

What goes wrong?

  • SCD Type 2 is still in preview, and not offered for Oracle sources yet, nor when you create the schema in the destination database yourself.
  • A deleted mapped column. With a column mapping, a source column that is dropped or renamed fails the run. A new column is ignored until you add it to the mapping.
  • Net changes only. A row updated five times between two runs arrives once, in its last state. If you need every step, run more often or read the CDC tables directly.
  • Lakehouse sources. Whether change data feed is on for a Fabric lakehouse table is not detected automatically; check it yourself.

Where can you check this?

Where do you start?

Pick the one source table where deletes matter most, usually customers or products, and move it to a Copy job of its own with CDC. How CDC works inside SQL Server is in change data capture in SQL Server, explained, what Type 1 and Type 2 mean for a report in slowly changing dimensions, and the watermark way in load only the rows that changed.

Keep reading

More from the blog.

Every post

Next

Building this? Say hello.

A question about this post, a pattern you would build differently, or the next thing you want written out: Behnia reads every message.