CertSafari
    Databricks Certified Data Analyst Associate· Lessons

    Domain 5 · Lesson 20/39

    Delta Lake table history: audit changes and compare versions

    Utilize Delta Lake to audit and view history, validate results, and compare historical results or trends.

    17 min read
    2.5% of exam
    6 sources
    Published 22 Oct 2026
    Docs as of 17 Oct 2026

    What you will be able to do

    • Run DESCRIBE HISTORY and read who changed a Delta table, when, and with which operation
    • Use operationParameters and operationMetrics to explain exactly what a commit did
    • Compare two table versions with EXCEPT or a key join to validate a change or measure a trend
    • Explain why history can list a version whose data can no longer be queried

    Key concept

    Table version — Every write to a Delta table commits a new, numbered version to the transaction log. DESCRIBE HISTORY lists those commits, and time travel can read any version that is still retained, so a version is both an audit record and a snapshot you can query.

    1.Auditing a table with DESCRIBE HISTORY

    A Delta table records every change it receives. When a nightly load doubles a row count, or a column suddenly fills with nulls, the first thing to find out is what touched the table, who ran it and when. Every insert, update, delete, merge or OPTIMIZE commits a new numbered version to the table's transaction log, and DESCRIBE HISTORY reads that log back as a result set with one row per commit.

    Newest commits come first, because rows are returned in reverse chronological order. That ordering gives LIMIT a useful meaning: LIMIT 1 returns only the most recent operation, and LIMIT 5 returns the last five. The table name has to be plain. A temporal specification such as VERSION AS OF is not allowed in the DESCRIBE HISTORY statement, because the command already covers every version. If you prefer a visual view, Catalog Explorer shows the same history on the table's History tab.

    Full history versus the latest commit onlysql
    DESCRIBE HISTORY table_name       -- get the full history of the table
    
    DESCRIBE HISTORY table_name LIMIT 1  -- get the last operation only

    The output has 14 columns, and each one answers a different audit question. For who and when, use userName, userId and timestamp. For where the change came from, use job and notebook: each is filled in only when the commit came from a Lakeflow job or a Databricks notebook, and is null otherwise. clusterId names the compute it ran on. readVersion is the version the write read before committing. In a long chain of edits you can follow it backwards: version 5 read version 4, which read version 3. Writes made over JDBC or ODBC, through the REST API, or from some job task types leave some of these columns empty.

    The DESCRIBE HISTORY columns grouped by the question each one answers
    Audit questionColumnWhat it records
    Which change?versionThe table version generated by the operation
    When?timestampWhen this version was committed
    Who?userId, userNameThe ID and name of the user that ran the operation
    What kind of change?operationThe operation name, such as WRITE, UPDATE, DELETE, MERGE or OPTIMIZE
    From where?job, notebook, clusterIdThe Lakeflow job or notebook (null if neither) and the cluster that ran it
    Based on what?readVersionThe table version read to perform the write
    How exactly?operationParameters, operationMetricsThe operation's parameters (for example, predicates) and its row and file counts
    Anything else?isolationLevel, isBlindAppend, userMetadataIsolation level, whether the operation appended data, and user-defined commit metadata

    Checkpoint 1 of 8· Fill the gap

    An analyst wants to see only the most recent commit to a Delta table. Which keyword completes the second statement?

    DESCRIBE HISTORY table_name       -- get the full history of the table
    
    DESCRIBE HISTORY table_name  ?  1  -- get the last operation only

    Checkpoint 2 of 8· Match them up

    You are investigating a suspicious commit. Match each DESCRIBE HISTORY column to what it tells you.

    Tap a term, then the definition that fits it.

    Sources123

    2.Reading operationParameters and operationMetrics

    The operation column gives only the type of change. Two map columns tell you what the change actually did. operationParameters holds the inputs the operation ran with. operationMetrics holds the measured result: how many rows and files the commit added, removed, updated or copied, plus timings. Neither column stores the SQL text of the statement, and neither holds the column statistics Delta uses for data skipping or the warehouse's configuration.

    operationParameters depend on the operation. A DELETE or UPDATE records its predicate, so the history row for a cleanup step shows the condition it applied, for example (spark_catalog.myschema.t.c1 = 3). An append records mode as Append. A CREATE TABLE records things like isManaged and the table properties. One field is easy to misread. partitionBy only means something on CREATE and OVERWRITE operations, and on appends it can show [] even though the rows still land in the correct partitions.

    operationParameters of an append to a table partitioned by date: the empty partitionBy is expectedjson
    operationParameters: {
      "mode": "Append",
      "partitionBy": "[]"
    }

    operationMetrics have different keys for each operation, and the key names describe themselves. A MERGE is the richest. It reports numSourceRows, then numTargetRowsInserted, numTargetRowsUpdated and numTargetRowsDeleted, then numTargetFilesAdded and numTargetFilesRemoved, along with executionTimeMs. Suppose a MERGE of a 10,000-row source shows 9,500 updates and 500 inserts. That confirms it matched most keys, and tells you whether a jump in row count came from inserts or from somewhere else. A DELETE reports numDeletedRows, and an UPDATE reports numUpdatedRows. Both also report numCopiedRows: rows that weren't changed but had to be rewritten because they shared a file with rows that were.

    Metrics to check first for common operations
    OperationKey metricsWhat they tell you
    WRITE (append or create)numFiles, numOutputRows, numOutputBytesHow many rows, files and bytes the load wrote
    MERGEnumSourceRows, numTargetRowsInserted, numTargetRowsUpdated, numTargetRowsDeletedHow the source rows were applied to the target
    UPDATEnumUpdatedRows, numCopiedRowsRows changed, and unchanged rows rewritten alongside them
    DELETEnumDeletedRows, numCopiedRows, numRemovedFilesRows removed, and files rewritten or dropped
    OPTIMIZEnumRemovedFiles, numAddedFiles, numRemovedBytes, numAddedBytesHow many small files were compacted into how many larger ones

    History is a query result, so you can filter it and pull individual map keys out of it. Wrap the command as FROM (DESCRIBE HISTORY table_name) and read keys with dot notation. This matters for OPTIMIZE. Auto compaction, liquid clustering and Z-ordering all show up as the same OPTIMIZE operation, and only the parameters tell them apart. Liquid clustering fills clusterBy, Z-ordering fills zOrderBy, and auto compaction sets auto to true.

    Classify every OPTIMIZE commit from its parameters and report its file metricssql
    SELECT
      version,
      timestamp,
      CASE
        WHEN operationParameters.clusterBy IS NOT NULL AND operationParameters.clusterBy <> '[]' THEN 'Liquid clustering'
        WHEN operationParameters.zOrderBy IS NOT NULL AND operationParameters.zOrderBy <> '[]' THEN 'Z-ordering'
        WHEN operationParameters.auto = 'true' THEN 'Auto compaction'
        ELSE 'Manual OPTIMIZE'
      END AS optimize_type,
      operationParameters.auto AS is_auto_compaction,
      operationParameters.clusterBy AS cluster_by,
      operationParameters.zOrderBy AS z_order_by,
      operationMetrics.numRemovedFiles AS files_compacted,
      operationMetrics.numAddedFiles AS files_added,
      operationMetrics.numRemovedBytes AS bytes_removed,
      operationMetrics.numAddedBytes AS bytes_added
    FROM (DESCRIBE HISTORY table_name)
    WHERE operation = 'OPTIMIZE'
    ORDER BY version DESC;

    Checkpoint 3 of 8· Check yourself

    A nightly job appends rows to a Delta table partitioned by date. In DESCRIBE HISTORY, that append's operationParameters show "mode": "Append" and "partitionBy": "[]". What should you conclude?

    Checkpoint 4 of 8· Exam question

    An analyst runs DESCRIBE HISTORY orders LIMIT 5; and wants to understand what the returned operationMetrics column contains for a row where operation is MERGE. What does that column represent?

    Sources341

    3.Comparing versions to validate a change or track a trend

    History tells you how much a commit changed. To see which rows changed, compare the data itself. Delta time travel (VERSION AS OF / TIMESTAMP AS OF / @) reads a table as it was at an earlier version, and the version numbers you need come straight from the version column of DESCRIBE HISTORY. Put two snapshots of the same table side by side and ordinary SQL shows the differences.

    EXCEPT gives you the row-level differences. It returns the rows of the first query that are missing from the second. Say Friday's load is version 11 and last night's job wrote version 12. Then SELECT * FROM inventory_counts VERSION AS OF 12 EXCEPT SELECT * FROM inventory_counts VERSION AS OF 11 returns rows that are new or changed in version 12. Swap the two queries to find rows that were removed or changed. Both sides need the same number of columns with compatible types. If a column was added between the two versions, list the columns explicitly instead of using *, or Databricks raises NUM_COLUMNS_MISMATCH. EXCEPT removes duplicates by default. Use EXCEPT ALL if you need to catch a row that was loaded twice.

    This is why metrics and a data comparison do different jobs. An OPTIMIZE commit reports large file counts in operationMetrics, yet the rows are unchanged. Comparing file or row counts from two history entries only estimates the difference and never names the rows. Rerunning OPTIMIZE or computing statistics doesn't compare versions at all. When the question is whether rows were unexpectedly added or removed, run EXCEPT on the two snapshots.

    A join on a business key compares values instead of whole rows. Join the current table to an earlier snapshot ON source.userId = target.userId and you can put each key's old and new values side by side, or filter to keys whose amount changed. The same pattern can repair a table: a MERGE whose source is the table as it was yesterday, joined on the key, puts back values that were updated by mistake.

    To track a trend, compare aggregates across time. Subtract an aggregate computed on an earlier snapshot from the same aggregate on the current table. The query below counts customers added in the last seven days without needing a created-date column. Change the offset, or point VERSION AS OF at successive versions, to build a week-over-week series.

    New customers in the last week: current distinct count minus the count from seven days agosql
    SELECT
    (
      SELECT count(distinct userId)
      FROM my_table
    )
    -
    (
      SELECT count(distinct userId)
      FROM my_table TIMESTAMP AS OF date_sub(current_date(), 7)
    ) AS new_customers

    Checkpoint 5 of 8· Check yourself

    The Delta table my_table has no created-date column, but a manager wants the number of distinct customers (userId) added in the last seven days. Which approach gives that number?

    Checkpoint 6 of 8· Exam question

    A finance analyst wants to compare last Friday's inventory_counts table against the version created by yesterday's overnight OPTIMIZE job, to check whether any rows were unexpectedly added or removed between the two loads. Which approach lets them compare the row-level differences between two specific historical versions of the same table?

    Sources561

    4.How long history is kept, and why it can outlive the data

    A table property sets how far back table history goes, not the table's age or a workspace rule. delta.logRetentionDuration controls how long the transaction log keeps history, and its default is interval 30 days. Log files are cleaned up automatically after checkpointing. So a table that has existed for a year normally shows about a month of entries in DESCRIBE HISTORY. Delta doesn't archive older commits to another table, and the command doesn't read from the warehouse's query history. To audit further back, raise the property with ALTER TABLE or set it when you create the table.

    Reading an old version needs both its log entry and its data files. Those two are kept on separate clocks. Time travel retention and VACUUM is governed by delta.deletedFileRetentionDuration, which defaults to 7 days. Under the defaults, then, a version between 8 and 30 days old can still appear in DESCRIBE HISTORY, with its user, operation and metrics, while a VERSION AS OF query against it fails. You can still audit what happened, but you can no longer run an EXCEPT comparison against that version.

    If you need a 30-day comparison window, raise data retention to match: setting delta.deletedFileRetentionDuration to interval 30 days lines it up with the log default. The cost is storage, because more old data files are kept. In Databricks Runtime 18.0 and above, the log retention must be at least as long as the deleted-file retention. Neither setting turns history into a backup. Plan on comparing versions from the past 7 days unless both retention settings have been raised.

    Checkpoint 7 of 8· Check yourself

    A team must be able to run EXCEPT comparisons against any version of a Delta table from the past 30 days. The table uses the default retention settings, and VACUUM runs regularly. What should they change?

    Checkpoint 8 of 8· Exam question

    A pipeline owner is auditing customer_events and finds that DESCRIBE HISTORY only returns entries going back 30 days, even though the table has existed for over a year. Why does the history stop at that point by default?

    Sources1

    Sources

    (6)

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 1.
      “Run the DESCRIBE HISTORY command to retrieve information including the operations, user, and timestamp for each write to a table.”
      ↩︎ Auditing a table with DESCRIBE HISTORY
      “The operations are returned in reverse chronological order.”
      ↩︎ Auditing a table with DESCRIBE HISTORY
      “Catalog Explorer shows table history visually on the History tab.”
      ↩︎ Auditing a table with DESCRIBE HISTORY
      “Auto compaction, liquid clustering, and Z-ordering all appear in table history as OPTIMIZE operations.”
      ↩︎ Reading operationParameters and operationMetrics
      “USING my_table TIMESTAMP AS OF date_sub(current_date(), 1) source ON source.userId = target.userId”
      ↩︎ Comparing versions to validate a change or track a trend
      “To query the number of new customers added over the last week:”
      ↩︎ Comparing versions to validate a change or track a trend
      “Table history retention is determined by the table setting logRetentionDuration, which is 30 days by default.”
      ↩︎ How long history is kept, and why it can outlive the data
      “Log files are removed automatically after checkpointing table versions.”
      ↩︎ How long history is kept, and why it can outlive the data
      “determines the threshold VACUUM uses to remove data files no longer referenced in the current table version. The default is interval 7 days.”
      ↩︎ How long history is kept, and why it can outlive the data
      “In Databricks Runtime 18.0 and above, logRetentionDuration must be greater than or equal to deletedFileRetentionDuration.”
      ↩︎ How long history is kept, and why it can outlive the data
      “Don't use table history as a long-term backup solution for data archival.”
      ↩︎ How long history is kept, and why it can outlive the data
      “each operation that modifies a table creates a new table version”
      ↩︎ Key concept
      “To query a previous table version, you must retain both the log and the data files for that version”
      ↩︎ Exam trap 4
      “No records. OPTIMIZE compaction does not change the data in the table.”
      ↩︎ Prediction
      “Time travel and table history are controlled by different retention thresholds.”
      ↩︎ Prediction
      “For example, to access 30 days of historical data, set delta.deletedFileRetentionDuration = "interval 30 days", which matches the default setting for delta.logRetentionDuration.”
      ↩︎ Checkpoint
    2. 2.
      “The name must not include a temporal specification or options specification.”
      ↩︎ Auditing a table with DESCRIBE HISTORY
    3. 3.
      “The DESCRIBE HISTORY command returns 14 columns for Apache Iceberg and Delta Lake tables that describe the history of table operations.”
      ↩︎ Auditing a table with DESCRIBE HISTORY
      “The version of the table that was read to perform the write operation.”
      ↩︎ Auditing a table with DESCRIBE HISTORY
      “If you write into a table using the following methods, some columns aren't available: JDBC or ODBC Run a command using the REST API”
      ↩︎ Auditing a table with DESCRIBE HISTORY
      “The parameters of the operation (for example, predicates.)”
      ↩︎ Reading operationParameters and operationMetrics
      “The metrics of the operation (for example, number of rows and files modified.)”
      ↩︎ Reading operationParameters and operationMetrics
      “numCopiedRows | The number of rows just copied over in the process of updating files.”
      ↩︎ Reading operationParameters and operationMetrics
      “The partitionBy field in table history is only meaningful for CREATE and OVERWRITE operations that define or change a table's partition schema.”
      ↩︎ Reading operationParameters and operationMetrics
      “The metrics of the operation (for example, number of rows and files modified.)”
      ↩︎ Exam trap 1
      “You shouldn't use it to validate append operations.”
      ↩︎ Exam trap 2
      “operationMetrics | map | The metrics of the operation (for example, number of rows and files modified.)”
      ↩︎ Checkpoint
      “The empty partitionBy value is expected. The data is still written to the correct partitions based on the table's existing partition schema.”
      ↩︎ Checkpoint
    4. 5.
      “version is a long value that can be obtained from the output of DESCRIBE HISTORY table_spec.”
      ↩︎ Comparing versions to validate a change or track a trend
    5. 6.
      “EXCEPT [ALL | DISTINCT ] Returns the rows in subquery1 which are not in subquery2.”
      ↩︎ Comparing versions to validate a change or track a trend
      “If the number of columns differs, Databricks raises NUM_COLUMNS_MISMATCH.”
      ↩︎ Comparing versions to validate a change or track a trend
      “Returns the rows in subquery1 which are not in subquery2.”
      ↩︎ Exam trap 3

    Spotted a mistake, or was something unclear? Tell us.