Sub topic 3
Reading table history with DESCRIBE HISTORY
This chapter assumes you can write basic SQL, run cells in a Databricks notebook or the SQL editor, and know what a Delta table is. It also assumes you have read the earlier chapters on the transaction log and table versions. Here you learn to read the history of a table, so you can pick the right version to query or restore later.
What DESCRIBE HISTORY returns
DESCRIBE HISTORY reads the Delta transaction log and returns one row per commit. Each commit is a table version, so the output is a list of everything that has changed the table. The newest commit comes first.
DESCRIBE HISTORY main.sales.orders LIMIT 10;The LIMIT 10 clause returns only the 10 most recent commits. Without it, the command returns every commit still kept in the log. On a busy table that can be thousands of rows, so a limit is a good habit.
The key columns
The output has many columns. These are the ones you will use most often.
| Column | What it tells you |
|---|---|
| `version` | The commit number. Version 0 is the first commit. |
| `timestamp` | When the commit was made. |
| `userName` | The user who ran the operation. |
| `operation` | The kind of change, such as `WRITE`, `MERGE`, `UPDATE`, `DELETE`, `OPTIMIZE`, or `RESTORE`. |
| `operationParameters` | Settings of the operation, such as the write mode or the predicate. |
| `operationMetrics` | Counts such as rows written, rows deleted, and files added. |
| `job` and `notebook` | Where the change came from, when it ran from a job or notebook. |
| `readVersion` | The version the operation read before it wrote. |
| `isolationLevel` | The isolation level used for the commit. |
Some columns can be empty. For example, notebook is empty for a change made from a job, and the contents of operationMetrics differ by operation.
Reading a result
Suppose the history of main.sales.orders looks like this, with some columns left out.
| version | timestamp | operation | operationMetrics (excerpt) |
|---|---|---|---|
| 7 | 2026-11-20 09:14:02 | DELETE | numDeletedRows: 1200 |
| 6 | 2026-11-19 02:00:11 | MERGE | numTargetRowsInserted: 340, numTargetRowsUpdated: 85 |
| 5 | 2026-11-18 02:00:09 | MERGE | numTargetRowsInserted: 310, numTargetRowsUpdated: 62 |
| 4 | 2026-11-17 16:30:45 | OPTIMIZE | numRemovedFiles: 48, numAddedFiles: 3 |
Read it from the top. Version 7 is a DELETE that removed 1,200 rows, and it ran in the morning, outside the nightly schedule that produced versions 5 and 6. If that delete was a mistake, version 6 is the last good state. You now have a version number to give to a time travel query or to RESTORE.
Version 4 shows that OPTIMIZE also creates a commit. It rewrote 48 small files into 3 larger ones but did not change the data. Not every version means the data changed.
Filtering the history
DESCRIBE HISTORY is a command, not a table, so you cannot add a WHERE clause to it directly. To filter, run it inside a notebook and turn the result into a DataFrame.
history = spark.sql("DESCRIBE HISTORY main.sales.orders")
(history
.where("operation IN ('DELETE', 'UPDATE', 'MERGE')")
.select("version", "timestamp", "userName", "operation", "operationMetrics")
.orderBy("version", ascending=False)
.show(truncate=False))This lists only the commits that changed rows. It is a quick way to find who ran a destructive statement and when.
In SQL, you can get the same result by selecting from the output of the last command with RESULT_SCAN-style tools in some environments. The PySpark approach works in every Databricks notebook, so this tutorial uses it.
Version numbers and timestamps
The version and timestamp columns are the two ways to point at a past state. A version number is exact. A timestamp selects the latest version committed at or before that moment.
The timestamp in the history is the commit time. It is not the time the data was created in your source system. If a nightly job loads yesterday's data at 02:00, the commit timestamp is 02:00 today. Use history to find the version, then confirm with a query.
How far back the history goes
DESCRIBE HISTORY only shows commits that are still in the log. Old entries are removed after the log retention period, which is 30 days by default. A later chapter covers the delta.logRetentionDuration setting. If a commit you expect is missing, retention is the most likely reason.
Common errors
- Table not found or permission denied. You need
SELECTon the table in Unity Catalog. Use the full three-part name,catalog.schema.table, if your current catalog is different. - Trying to filter in SQL. Writing
DESCRIBE HISTORY t WHERE operation = 'DELETE'is a syntax error. Use the DataFrame approach above. - Assuming every version is a data change.
OPTIMIZEand other maintenance commits appear in the history. Check theoperationcolumn before assuming rows changed. - Guessing from timestamps in another time zone. Compare the history timestamp against the session time zone before you pick a point in time.
Exercise
A table's history shows version 12 as a DELETE with numDeletedRows of 50000, run at 11:03 by a user, and version 11 as a MERGE from the nightly job. You want to inspect the data as it was before the delete. Which version do you query, and which column told you the delete was large?
Show answer
Query version 11, which is the last commit before the delete. The numDeletedRows value inside the operationMetrics column showed that 50000 rows were removed.
Exercise
Why does DESCRIBE HISTORY main.sales.orders WHERE operation = 'DELETE' fail, and how do you get the same result?
Show answer
DESCRIBE HISTORY is a command and does not accept a WHERE clause. Run it with spark.sql("DESCRIBE HISTORY main.sales.orders") to get a DataFrame, then filter that DataFrame with .where("operation = 'DELETE'").