What you will be able to do
- Enable legacy Change Data Feed on new and existing Delta tables, and predict what happens when it is disabled, re-enabled or set as a session default
- Interpret the _change_type, _commit_version and _commit_timestamp columns of change records, including update pre- and post-images and deletes
- Read a bounded range of changes with table_changes or readChangeFeed and tell it apart from time travel and DESCRIBE HISTORY
- Design a downstream pipeline that applies only changed rows to silver or gold tables and tracks the last processed version
Key concept
Change Data Feed (CDF) — A per-version log of row-level changes to a table. Each changed row is returned with its data and with metadata saying whether it was inserted, updated or deleted, and in which commit. Downstream jobs can then read only what changed instead of the whole table.
1.Why downstream tables need row-level changes
A silver table built from a 500-million-row bronze table should not have to reread all 500 million rows because forty of them changed overnight. Change Data Feed (CDF) solves this. For every committed version of a Delta table, it can return the rows that version inserted, updated or deleted, and tag each row with the kind of change and the version it came from. Incremental ETL, audit trails and replication to downstream tables or external systems all rely on this.
Reading the table directly with a plain stream doesn't solve the problem. Structured Streaming reads a Delta table as an append-only source. Once an UPDATE, DELETE, MERGE INTO or overwrite touches the source, a stream reading it fails. The other options each give something up. skipChangeCommits keeps the stream running by ignoring modifications. A full refresh reprocesses everything. A materialized view propagates changes automatically, but with higher latency, and only in Lakeflow pipelines and Databricks SQL. CDF is the only one of these that delivers all three change types to code you control.
| Approach | What propagates | Cost or limitation |
|---|---|---|
| skipChangeCommits | Appends only; updates and deletes are ignored | Changes are not propagated downstream |
| Full refresh | Everything, by recomputing | Expensive for large datasets; requires reprocessing all downstream tables |
| Change data feed | Inserts, updates and deletes | You write logic to handle each change type |
| Materialized views | Automatic change propagation | Higher latency; only in Lakeflow pipelines and Databricks SQL |
Databricks has two ways to produce a change feed. Legacy CDF works only on Delta Lake tables. It records the changes when data is written and must be turned on for each table with delta.enableChangeDataFeed. Automatic CDF works out the changes when you read them, using row tracking on Delta tables or row lineage on Iceberg v3 tables. It needs Databricks Runtime 19 or above and a table registered in Unity Catalog, but no per-table setting. Because automatic CDF does no extra work when MERGE INTO and UPDATE write data, writes are faster and storage costs less. Both use the same read APIs, table_changes() and readChangeFeed, so everything about reading changes on this page applies to both.
Checkpoint 1 of 8· Match them up
A streaming job reads a Delta table that upstream jobs sometimes update and delete. Match each way of handling those modifications to what it does.
Tap a term, then the definition that fits it.
Only the change data feed passes all three change types to your own downstream logic. skipChangeCommits drops updates and deletes, a full refresh reprocesses the whole dataset, and materialized views propagate changes automatically but have higher latency and only run on certain platforms.
“Change data feed | Process all change types (inserts, updates, and deletes).”Source: docs.databricks.com
2.Turning the legacy feed on and off
Legacy CDF is a table property, and you can set it in either of two places. For a new table, put delta.enableChangeDataFeed = true in the TBLPROPERTIES clause of CREATE TABLE. For a table that already exists, set the same property with ALTER TABLE ... SET TBLPROPERTIES. Neither requires converting the table to another format: legacy CDF is a Delta Lake feature.
ALTER TABLE your_catalog.your_schema.your_table
SET TBLPROPERTIES (delta.enableChangeDataFeed = true)A SparkSession setting won't enable CDF on tables that already exist. Session configurations can set default property values for new tables, and those defaults only apply to tables created afterwards. They don't change the properties of tables that already exist. To add CDF to an existing table, you still run ALTER TABLE on that table.
The feed starts at the commit where you enable it. It is not backfilled. Changes made before CDF was enabled are not recorded, and asking table_changes for a version from before then raises an error. Turning the property off and on again works the same way. Legacy CDF can be disabled with UNSET TBLPROPERTIES, and any commits made while it was off are a permanent gap in the feed. Disabling it is also the first step when you migrate a table to automatic CDF, because you can't run the legacy and automatic feeds on the same table.
ALTER TABLE <table_name> UNSET TBLPROPERTIES ('delta.enableChangeDataFeed');The legacy feed affects storage in three ways. First, change data may be written to separate files, which adds a small amount to storage costs. Second, some operations, such as insert-only writes and deletes of whole partitions, write no change files at all; for those, Databricks computes the feed from the transaction log. Third, change files follow the table's retention policy, so VACUUM deletes them. Always read changes through the APIs, never by querying the change files directly.
Checkpoint 2 of 8· Check yourself
An existing Delta table is at version 40 when an engineer runs ALTER TABLE ... SET TBLPROPERTIES (delta.enableChangeDataFeed = true). That commit becomes version 41. What does the change feed contain from then on?
Legacy CDF starts at the commit where it is enabled and is never backfilled, so asking for an earlier version raises an error. Commits made while the property is unset are a permanent gap in the feed. A session default only affects tables created after it is set.
“It only records changes that occur after change data feed was enabled.”Source: docs.databricks.com
Checkpoint 3 of 8· Exam question
A platform team is documenting how Change Data Feed can be enabled and what happens if it is toggled off and back on for a Delta table. Which of the following statements are correct?(Select 3)
Correct answers: A, B, D — Running ALTER TABLE sales.transactions SET TBLPROPERTIES (delta.enableChangeDataFeed = true) turns on Change Data Feed immediately, without rewriting any existing data files.; A new table can enable Change Data Feed at creation time by including delta.enableChangeDataFeed = true in its TBLPROPERTIES clause within the CREATE TABLE statement.; If legacy Change Data Feed is disabled on a table and then re-enabled later, the interval during which it was disabled remains a gap that cannot be queried through the change feed.
- A. Setting the
delta.enableChangeDataFeedtable property withALTER TABLE ... SET TBLPROPERTIESis the documented way to turn on change tracking for an already-existing table. No backfill or rewrite of prior data files is needed; the table simply starts recording row-level changes from that point forward. - B. Including
delta.enableChangeDataFeed = truein theTBLPROPERTIESclause of aCREATE TABLEstatement enables the feature from the table's very first commit. This is the standard pattern for new tables that are known to need downstream incremental consumers. - C. A session-level default property only controls the setting applied to tables created after that session configuration is set. It has no retroactive effect on tables that already exist, so existing tables keep whatever setting they already had.
- D. This describes a real limitation of legacy Change Data Feed: toggling it off and back on leaves an unqueryable interval corresponding to the disabled period. Teams that need continuous coverage should avoid disabling it, or move to the automatic Change Data Feed mechanism instead.
- E. The property can be unset with
ALTER TABLE ... UNSET TBLPROPERTIES ('delta.enableChangeDataFeed'), so it is not a permanent, one-way setting. Treating it as irreversible would incorrectly rule out a supported and commonly used administrative action. - F. Change Data Feed for standard Delta tables has long been available without any Iceberg conversion, using the
delta.enableChangeDataFeedtable property described above. Requiring Iceberg storage is not a real prerequisite for this feature on Delta tables.
3.Reading a change record
A change feed returns every column of the table, in the schema of the latest table version, plus three metadata columns. These columns are what downstream logic branches and sorts on.
| Column | Type | Meaning |
|---|---|---|
| _change_type | STRING NOT NULL | One of insert, update_preimage, update_postimage, delete |
| _commit_version | BIGINT NOT NULL | Table version whose commit contained the change |
| _commit_timestamp | TIMESTAMP NOT NULL | Timestamp at which that commit was created |
The example below makes four commits to a small table. Versions 1 and 2 insert rows. Version 3 upper-cases two values. Version 4 deletes a row.
-- Create a Delta table with Change Data Feed;
> CREATE TABLE myschema.t(c1 INT, c2 STRING) TBLPROPERTIES(delta.enableChangeDataFeed=true);
-- Modify the table
> INSERT INTO myschema.t VALUES (1, 'Hello'), (2, 'World');
> INSERT INTO myschema.t VALUES (3, '!');
> UPDATE myschema.t SET c2 = upper(c2) WHERE c1 < 3;
> DELETE FROM myschema.t WHERE c1 = 3;> SELECT * FROM table_changes('`myschema`.`t`', 2);
c1 c2 _change_type _commit_version _commit_timestamp
3 ! insert 2 2022-09-01T18:32:28.000+0000
2 WORLD update_postimage 3 2022-09-01T18:32:32.000+0000
2 World update_preimage 3 2022-09-01T18:32:32.000+0000
1 Hello update_preimage 3 2022-09-01T18:32:32.000+0000
1 HELLO update_postimage 3 2022-09-01T18:32:32.000+0000
3 ! delete 4 2022-09-01T18:32:35.000+0000The output shows what each change type carries:
- An
insertrow holds only the new values, because the row had no earlier state. - An update produces a pair in one commit.
update_preimageholds the old values (World) andupdate_postimageholds the new ones (WORLD), so you can compare before and after without a second query. - A
deleterow appears once and carries the row's last values (3, !), so you never have to look up what was removed.
These four strings are the only values _change_type can take. A MERGE INTO that inserts some rows and updates others still writes insert rows and pre/post-image pairs; there is no upsert type. The commit columns are NOT NULL for every change type, so you can always sort inserts, updates and deletes by _commit_version. The change types are also not SQL clauses: you still have to map them onto WHEN MATCHED and WHEN NOT MATCHED logic yourself.
Checkpoint 4 of 8· Check yourself
In one MERGE INTO commit (version 12), 2 source rows match no target row and are inserted, and 3 source rows match existing target rows and update them. What does table_changes return for version 12?
_change_type has only four values, and there is no upsert type. A MERGE writes an insert row for each new row and an update_preimage/update_postimage pair for each updated row, all in the same commit version.
“Contains: insert, update_preimage, update_postimage, delete.preimage is the value before the update, postimage is the value after the update.”Source: docs.databricks.com
Checkpoint 5 of 8· Exam question
A team reads Change Data Feed output from finance.ledger and writes Python logic that branches on the _change_type column to route rows to an audit table. Which statements about the _change_type values are correct?(Select 3)
Correct answers: A, B, E — Each source-table UPDATE produces two rows tagged update_preimage and update_postimage, letting the routing logic compare a record's value before and after the change within the same commit.; A deleted row appears exactly once with _change_type set to delete, carrying the row's last known column values, so the routing logic does not need to reconstruct the deleted content from elsewhere.; Newly inserted rows are tagged with _change_type equal to insert and carry only the new column values, since there is no prior version of the row to compare against.
- A. Updates are represented as a paired pre-image and post-image row so consumers can see both the old and new state of the changed record. This pairing is exactly what lets downstream logic compute field-level diffs for auditing.
- B. A delete is recorded as a single row carrying the last known values of the deleted record, tagged accordingly. This means the routing logic already has everything it needs to log what was deleted without a separate lookup.
- C. The four tag values describe what happened to a row, but they are not themselves valid
MERGEclause syntax and require the calling code to translate them into the appropriate insert, update, or delete action. The premise that branching logic becomes unnecessary is incorrect. - D. There is no
upsertvalue in the change feed; aMERGEthat inserts some rows and updates others produces ordinaryinsertand pairedupdate_preimage/update_postimagerows for the respective operations. Treatingupsertas a real tag would cause the routing logic to silently miss those rows. - E. New rows have nothing to compare against, so they are tagged as a plain insert carrying only the new values, unlike updates which carry a before-and-after pair. This asymmetry is expected and by design.
- F. Commit version and commit timestamp metadata are populated for every change event, not only deletes, because they describe the transaction that produced the row rather than the row's own change type. Excluding inserts and updates from that metadata would break the ability to order any change chronologically.
4.Reading a bounded range of versions
In SQL, batch reads use table_changes(table_str, start [, end]). In Python, they use spark.read with readChangeFeed. A start version is required for batch reads. If you pass an end version, the read stops there; if you leave it out, it reads to the latest commit. Both bounds are inclusive, so table_changes('analytics.orders', 12, 18) returns every change committed in versions 12 through 18. Bounds can also be timestamps, written as strings in the format yyyy-MM-dd[ HH:mm:ss[.SSS]]. Calling the function requires SELECT on the table, ownership of it, or admin privileges.
spark.read \
.option("readChangeFeed", "true") \
.option("startingVersion", 0) \
.option("endingVersion", 10) \
.table("myDeltaTable")table_changes raises an error for a bound earlier than the earliest available version, and for one later than the latest version or latest commit timestamp. Old versions disappear on schedule. The feed is transient: when the transaction log removes table versions, their change records go with them. A job that falls far enough behind can find that the versions it needs no longer exist. If you need a permanent change history, copy the feed into a table of its own.
Two other features look like they answer the same question but don't. VERSION AS OF time travel returns the whole table as it was at one version, and comparing two snapshots to work out what changed is exactly the full-scan work CDF avoids. DESCRIBE HISTORY lists one row per commit, with its operation, user, timestamp and parameters, but none of the row data that changed.
It shows only the net difference between two snapshots. A row inserted in version 13 and deleted in version 16 is missing from both snapshots, and two successive updates collapse into one. table_changes(t, 12, 18) returns every individual event with its _change_type and _commit_version, and doesn't scan either snapshot in full.
Checkpoint 6 of 8· Fill the gap
This batch read must return every change committed in versions 0 through 10, with version 10 included and nothing after it. Which value completes the endingVersion option?
spark.read \
.option("readChangeFeed", "true") \
.option("startingVersion", 0) \
.option("endingVersion", ? ) \
.table("myDeltaTable")Both the start and end bounds of a change feed read are inclusive, so endingVersion 10 already includes version 10. Passing 11 would also return the changes from version 11, and passing 9 would leave out version 10.
Source: docs.databricks.comCheckpoint 7 of 8· Exam question
A downstream job must audit exactly the row-level changes that occurred between Delta version 12 and version 18, inclusive, on analytics.orders, which has Change Data Feed enabled. Which SQL statement retrieves precisely this range of changes?
Correct answer: A — SELECT * FROM table_changes('analytics.orders', 12, 18), which passes the starting and ending version bounds to the change feed table-valued function and returns every row-level change recorded between those two committed versions.
- A. The
table_changesfunction is the documented way to read Change Data Feed output in SQL, and supplying a starting and ending version bounds the result to exactly the commits in that inclusive range. This is the most direct and correct way to satisfy the audit requirement. - B. Time-travel snapshots via
VERSION AS OFreturn the complete state of the table at a single version, not the discrete change events between two versions. Diffing two full snapshots client-side would be both incorrect for updates that were later overwritten and far more expensive than reading the change feed directly. - C.
TIMESTAMP AS OFrequires a timestamp literal rather than an integer version number, so this statement is malformed as written. It also never invokes the change feed mechanism, so the resulting rows would lack the_change_typeand_commit_versioncolumns needed for the audit. - D.
DESCRIBE HISTORYis useful for inspecting operation-level metadata like who ran aMERGEand when, but it does not return the underlying row data that was inserted, updated, or deleted. It cannot substitute for reading the actual change feed content.
5.Applying only changed rows downstream
For incremental processing, Databricks recommends streaming from a table's change feed rather than from the table itself, wherever possible. Set readChangeFeed to true on spark.readStream. The checkpoint then records which versions have been processed, and Databricks only tracks versions automatically when you use Structured Streaming. Each run picks up from the next unprocessed commit. With trigger(availableNow=True), the stream becomes a scheduled incremental batch that processes the backlog and stops. Checkpoints and triggers themselves are covered in Structured Streaming state and checkpoints.
Watch the first run. A new CDF stream with no starting version first returns the table's current snapshot as insert records, then the changes after it. That is what a brand-new target needs. If the target already holds the data up to some version, set startingVersion so the snapshot isn't loaded again as duplicate inserts.
The changed rows still have to be merged into the silver or gold table. A typical MERGE keyed on the business key:
- Filters out
update_preimagerows, because the postimage already holds the updated row. - Deletes the matched target row when
_change_type = 'delete'. - Updates matched rows and inserts unmatched ones from the remaining
insertandupdate_postimagerows. - Keeps only the latest event for each key in the batch, ranked by
_commit_version(or_commit_timestamp), so the newest change to a key is the one that wins.
The same events can instead feed a declarative flow that does this reconciliation for you; see AUTO CDC with SCD types.
Step 4 matters because one read of the feed can return several events for the same key. A single logical change already produces more than one: moving one product to a new warehouse yields an insert, an update_preimage and an update_postimage for that product across the versions read. A batch that spans several commits can also hold an insert, then two updates, then a delete for one key. Merging all of them as they come leaves the outcome dependent on event order rather than on commit order. Rank the rows within each key before the merge: after dropping preimages, number them with ROW_NUMBER() OVER (PARTITION BY <key> ORDER BY _commit_version DESC) and keep only the rows numbered 1. Run the MERGE from that result, so each key meets the target once. Its _change_type then decides the action: delete the target row for delete, otherwise update or insert.
Each run touches only the new commits. In a Databricks SQL tutorial, a streaming table built from a product table's change feed was refreshed after two products were deleted with DELETE FROM products WHERE product_id = 9; and the same for product 10. The refresh processed only those two delete events, closed out the two products' records, and left the earlier inserts and updates alone. To track progress yourself in a batch job, record the highest _commit_version written to the target; the next read starts one version later.
(spark.readStream
.option("readChangeFeed", "true")
.option("startingVersion", 76)
.table("source_table")
.writeStream
.option("checkpointLocation", "<new-checkpoint-path>")
.toTable("target_table")
)Two conditions must hold for this restart to work. The stream writing to the existing target must use a new checkpoint location, and version 76 must still be in the source history. If that version has already been cleaned up, the stream fails to start. On managed tables, every starting version you might choose is eventually deleted, so recover soon after a checkpoint fails.
Checkpoint 8 of 8· Fill the gap
A stream's checkpoint is corrupted. The existing target table already holds every change through version 75 of the source. The replacement stream must not reload the source's current state as duplicate insert records. Which option completes the sample?
(spark.readStream
.option("readChangeFeed", "true")
.option(" ? ", 76)
.table("source_table")
.writeStream
.option("checkpointLocation", "<new-checkpoint-path>")
.toTable("target_table")
)If a new CDF stream has no starting version, its first run emits the table's current snapshot as insert records. startingVersion 76 skips the state the target already holds and resumes at the first commit it has not processed. endingVersion only caps a range, and skipChangeCommits would drop updates and deletes.
Source: docs.databricks.comPractise it for real
Create a CDF-enabled table, generate inserts, updates and deletes, and read them back by version range
1.Run CREATE TABLE myschema.t(c1 INT, c2 STRING) TBLPROPERTIES(delta.enableChangeDataFeed=true);
Why: Turns on legacy CDF at creation, so every later commit is recorded
You should see: DESCRIBE HISTORY shows version 0, CREATE TABLE, with delta.enableChangeDataFeed true in its properties
2.Insert (1,'Hello'),(2,'World'), then (3,'!'), then UPDATE myschema.t SET c2 = upper(c2) WHERE c1 < 3, then DELETE FROM myschema.t WHERE c1 = 3
Why: Produces one commit of each kind of change
You should see: DESCRIBE HISTORY lists versions 1 to 4 as WRITE, WRITE, UPDATE, DELETE
3.Run SELECT * FROM table_changes('
myschema.t', 2);Why: Reads every change from version 2 to the latest
You should see: Six rows: one insert at version 2, two pre/post pairs at version 3, one delete at version 4
4.Run SELECT * FROM table_changes('
myschema.t', 3, 3);Why: Shows that both bounds are inclusive
You should see: Only the four update_preimage and update_postimage rows from version 3
Stuck? Get a nudge
If a read fails with an out-of-range error, check the start and end versions against DESCRIBE HISTORY.
Sources
(6)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.
“Structured Streaming only accepts append inputs and throws an exception if any modifications occur on the source Delta Lake table.”
↩︎ Why downstream tables need row-level changes“Databricks recommends streaming from the CDC feed of a Delta Lake table rather than directly from the table whenever possible.”
↩︎ Applying only changed rows downstream“Change data feed | Process all change types (inserts, updates, and deletes).”
↩︎ Checkpoint - 2.
“Legacy change data feed: Materializes changes during table writes. Only supports Delta Lake tables. Requires individual table configuration.”
↩︎ Why downstream tables need row-level changes“Automatic change data feed computes row-level changes at query time rather than at write time”
↩︎ Why downstream tables need row-level changes“Set the table property delta.enableChangeDataFeed = true in the ALTER TABLE command.”
↩︎ Turning the legacy feed on and off“If you specify a version before change data feed was enabled, it raises an error.”
↩︎ Turning the legacy feed on and off“You can't use both legacy and automatic change data feeds together.”
↩︎ Turning the legacy feed on and off“You might see small increase in storage costs because changes might be recorded in separate files.”
↩︎ Turning the legacy feed on and off“If the schema contains columns with the same names as these metadata columns, you can't use change data feed on a table.”
↩︎ Turning the legacy feed on and off“When you read from the change data feed for a table, the query uses the schema for the latest table version.”
↩︎ Reading a change record“Start and end versions are inclusive. To read from a starting version to the latest version, specify only the starting version.”
↩︎ Reading a bounded range of versions“Records in the change data feed are transient and only accessible for a specified retention window.”
↩︎ Reading a bounded range of versions“You must use Structured Streaming for Databricks to automatically track versions for your table's change data feed.”
↩︎ Applying only changed rows downstream“change data feed returns the latest snapshot of the table as INSERT records and then returns future changes as change data”
↩︎ Applying only changed rows downstream“When you define the write stream to the existing target table, you must specify a new checkpoint location:”
↩︎ Applying only changed rows downstream“Because managed tables clean up historic versions automatically, all specified starting versions are eventually deleted.”
↩︎ Applying only changed rows downstream“Change data feed (CDF) tracks row-level changes between versions of a Delta Lake table or Apache Iceberg v3 table.”
↩︎ Key concept“It only records changes that occur after change data feed was enabled.”
↩︎ Exam trap 2“Start and end versions are inclusive.”
↩︎ Exam trap 4“specify a starting version to avoid processing the source table state as INSERT events.”
↩︎ Exam trap 5“It only records changes that occur after change data feed was enabled.”
↩︎ Checkpoint“preimage is the value before the update, postimage is the value after the update.”
↩︎ Prediction“Contains: insert, update_preimage, update_postimage, delete.preimage is the value before the update, postimage is the value after the update.”
↩︎ Checkpoint - 3.
“These defaults only apply to new tables and don't affect existing table properties.”
↩︎ Turning the legacy feed on and off“These defaults only apply to new tables and don't affect existing table properties.”
↩︎ Exam trap 1 - 4.
“_commit_version BIGINT NOT NULL Specifies the commit version of the table associated with the change.”
↩︎ Reading a change record“A version earlier than the earliest available version of the table.”
↩︎ Reading a bounded range of versions“_change_type STRING NOT NULL Specifies the change: delete, insert, update_preimage, or update_postimage”
↩︎ Exam trap 3 - 5.
“Delta tables (each table version is effectively a snapshot)”
↩︎ Reading a bounded range of versions - 6.
“WHERE _change_type != 'update_preimage': skips preimages. The postimage already has the updated row.”
↩︎ Applying only changed rows downstream“a single logical change (for example, moving the Spoon to a different warehouse) produces multiple events: a preimage and a postimage.”
↩︎ Applying only changed rows downstream“The streaming table only processed the new delete events without reprocessing the inserts and updates from the previous refresh.”
↩︎ Applying only changed rows downstream