---
title: Transactions
description: Run multiple SQL statements as a single atomic transaction on Unity Catalog tables on Databricks. All changes succeed or roll back together, guaranteeing data consistency.
canonical_url: https://docs.databricks.com/aws/en/transactions/
---

# Transactions

Transactions allow you to coordinate operations across multiple SQL statements and tables. All changes succeed together or roll back together, ensuring data consistency across your operations and tables. Transactions include ACID properties: atomicity, consistency, isolation, and durability. See [What are ACID guarantees on Databricks?](https://docs.databricks.com/aws/en/lakehouse/acid.md).

Transactions can be used with [stored procedures](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-create-procedure.md) and [SQL Scripting](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-scripting.md) to build mission-critical warehousing workloads.

The following example shows a transaction:

## Non-interactive

```sql
BEGIN ATOMIC
  UPDATE accounts SET balance = balance - 100 WHERE id = 1;
  UPDATE accounts SET balance = balance + 100 WHERE id = 2;
  INSERT INTO audit_log VALUES (1, 2, 100, current_timestamp());
END;
```

## Interactive

```sql
BEGIN TRANSACTION;
UPDATE accounts SET balance = balance - 100 WHERE id = 1;
UPDATE accounts SET balance = balance + 100 WHERE id = 2;
INSERT INTO audit_log VALUES (1, 2, 100, current_timestamp());
COMMIT;
```

All three statements commit together. If any statement fails, all changes roll back and Databricks terminates the transaction without side effects.

For hands-on practice with transactions, see [Tutorial: Coordinate transactions across tables](https://docs.databricks.com/aws/en/transactions/tutorial.md).

## <a id="requirements" />Requirements

To run transactions that span multiple statements or multiple tables:

* All tables written to must:
  * Be Unity Catalog managed tables (Delta Lake or Iceberg)
  * Have [Catalog commits](https://docs.databricks.com/aws/en/tables/features/catalog-commits.md) enabled
* Use supported compute:
  * For **non-interactive transactions**, use any SQL warehouse, [serverless compute](https://docs.databricks.com/aws/en/compute/serverless/index.md), or [cluster](https://docs.databricks.com/aws/en/compute/index.md) running Databricks Runtime 18.0 and above.
  * For **interactive transactions**, use any SQL warehouse.
  * For **transactions on OpenSharing shared assets**, use Databricks Runtime 18.1 and above.

## <a id="transaction-modes" />Transaction modes

Databricks supports two transaction modes:

| Mode            | Syntax                                                                                                                                                                                                  | Commit               | Rollback           | Best for                                                        |
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------- | ------------------ | --------------------------------------------------------------- |
| Non-interactive | [ATOMIC compound statement](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-txn-begin-atomic.md)                                                                                  | Automatic on success | Automatic on error | Fixed sequences, scheduled jobs                                 |
| Interactive     | [BEGIN TRANSACTION](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-txn-begin.md); [COMMIT](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-txn-commit.md); | Manual               | Manual             | Conditional logic, validation and debugging, JDBC, ODBC, PyODBC |

For detailed syntax, examples, and usage patterns for both modes, see [Transaction modes](https://docs.databricks.com/aws/en/transactions/transaction-modes.md).

## <a id="supported-operations" />Supported operations

You can use the following operations within transactions:

| Operation                                                                                                                                                                                                         | Description                                                                                                                       |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
| [`SELECT` (subselect)](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-qry-select.md)                                                                                                       | Query data and validate results                                                                                                   |
| [`VALUES` clause](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-qry-select-values.md)                                                                                                     | Generate test data or constant values                                                                                             |
| [`INSERT`](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-dml-insert-into.md) (including all variants)                                                                                     | Add new rows                                                                                                                      |
| [`UPDATE`](https://docs.databricks.com/aws/en/sql/language-manual/delta-update.md)                                                                                                                                | Modify existing rows                                                                                                              |
| [`COPY INTO`](https://docs.databricks.com/aws/en/sql/language-manual/delta-copy-into.md)                                                                                                                          | Load data from a file into a Delta table                                                                                          |
| [`DELETE FROM`](https://docs.databricks.com/aws/en/sql/language-manual/delta-delete-from.md)                                                                                                                      | Remove rows                                                                                                                       |
| [`MERGE INTO`](https://docs.databricks.com/aws/en/sql/language-manual/delta-merge-into.md)                                                                                                                        | Upsert patterns combining insert, update, and delete                                                                              |
| [USE CATALOG](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-use-catalog.md) and [USE SCHEMA](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-ddl-use-schema.md) | Set the current catalog or schema for statements in the transaction                                                               |
| [EXECUTE IMMEDIATE](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-aux-execute-immediate.md)                                                                                               | Run a SQL statement that you construct dynamically at run time                                                                    |
| [DESCRIBE TABLE](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-aux-describe-table.md)                                                                                                     | Return metadata about a table, such as its columns and properties                                                                 |
| [SHOW COLUMNS](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-aux-show-columns.md)                                                                                                         | List the columns in a table                                                                                                       |
| [GET DIAGNOSTICS statement](https://docs.databricks.com/aws/en/sql/language-manual/control-flow/get-diagnostics-stmt.md)                                                                                          | Retrieve diagnostic information, such as the active-transaction state or the number of rows affected by the most recent statement |

## <a id="read-sources" />Supported read sources and write sinks

Transactions allow you to read from Unity Catalog tables (Delta Lake and Iceberg), streaming tables, views, and materialized views.

Delta Lake and Iceberg tables (including streaming tables) provide ACID guarantees, so they're supported in transactions as both read sources and write sinks. To read from non-transactional sources, use the `allow_nontransactional_read` hint. See [Read from non-transactional sources](https://docs.databricks.com/aws/en/transactions/index.md#nontransactional-sources) and [Example: non-transactional read](https://docs.databricks.com/aws/en/transactions/index.md#example-nontransactional-hint).

## <a id="nontransactional-sources" />Read from non-transactional sources

> [!WARNING]
>
> Non-transactional reads are not repeatable. Concurrent changes to the source data during the transaction might result in inconsistent reads.

Transactions allow you to read from non-transactional sources. Non-transactional sources include external tables using Parquet, Avro, CSV, and JSON file formats, and [federated tables using JDBC](https://docs.databricks.com/aws/en/query-federation/index.md). To read non-transactional sources, reference the source by name and use the `allow_nontransactional_read` hint.

Within a transaction, you can also query the [`information_schema`](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-information-schema.md).

You can read files directly with the [`read_files`](https://docs.databricks.com/aws/en/sql/language-manual/functions/read_files.md) table-valued function.

Path-based access is not supported. If you reference a file directly by path instead, such as `` FROM parquet.`/path/to/data` ``, the transaction fails with a `PATH_BASED_ACCESS` error.

The following code example shows how to use the hint on an external table using JSON:

```sql
BEGIN TRANSACTION;
-- Non-transactional source, hint required
INSERT INTO transactional_table
SELECT col1, col2
FROM external_json_table
WITH (allow_nontransactional_read = true);

COMMIT;
```

### <a id="example-nontransactional-hint" />Example: non-transactional read

The following example shows a non-transactional read from an external table using Parquet. This example requires you to have an existing external location with read and write access.

See [Connect to an AWS S3 external location](https://docs.databricks.com/aws/en/connect/unity-catalog/cloud-storage/s3/index.md).

To register the Parquet source as a named external table, run the following:

```sql
CREATE TABLE main.default.external_parquet_table
USING PARQUET
LOCATION 's3://my-bucket/path/to/data'; -- existing external location
```

To read both a non-transactional Parquet source and a managed table using Delta Lake in a transaction, run the following:

```sql
BEGIN ATOMIC
-- Non-transactional source, hint required
INSERT INTO transactional_table
SELECT col1, col2
FROM external_parquet_table
WITH (allow_nontransactional_read = true);

-- Managed table source, no hint is required
INSERT INTO another_table
SELECT * FROM managed_delta_table;
END;
```

## <a id="isolation" />Transaction isolation

Transactions allow repeatable reads across all statements. When you access a table in a transaction, Databricks captures a consistent snapshot of that table at first access. All subsequent reads of that table use this snapshot, so your reads remain consistent even if other users concurrently modify the same tables.

In the following example, the first query to `products` in the transaction captures a consistent snapshot:

### Non-interactive

```sql
BEGIN ATOMIC
  SELECT * FROM products WHERE product_id = 1001;
  SELECT * FROM products WHERE product_id = 1001;
END;
```

### Interactive

```sql
BEGIN TRANSACTION;
SELECT * FROM products WHERE product_id = 1001;
SELECT * FROM products WHERE product_id = 1001;
COMMIT;
```

Then, assume another user concurrently updates the row for `product_id = 1001` before the second query begins:

```sql
UPDATE products SET price = 29.99 WHERE product_id = 1001;
```

Because the snapshot was captured at first access, the second query to `products` returns the original row, not the updated one.

### <a id="conflict-detection" />Conflict detection and concurrency

Databricks uses optimistic concurrency control. Transactions proceed without locking, and conflicts are detected at commit time. When you commit, Databricks checks each table written by the transaction to determine whether other transactions modified the same data after your transaction began. If conflicts exist, your transaction fails. For non-interactive transactions, the rollback also happens automatically. For interactive transactions, you must explicitly run `ROLLBACK` to clear the transaction state before beginning a new transaction.

Non-interactive transactions support row-level concurrency. Two transactions can modify different rows in the same data file without conflicting when [Row-level concurrency](https://docs.databricks.com/aws/en/optimizations/isolation/row-level-concurrency.md) is enabled on the target tables.

Interactive transactions support table-level concurrency.

### Conflict scenarios

| Scenario               | Description                                                                                                                                  |
| ---------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| Write-write conflicts  | Two transactions update or delete the same rows.                                                                                             |
| Write-read conflicts   | On a table written by the transaction, another transaction modified rows that your transaction read. Applies to Serializable isolation only. |
| Phantom read conflicts | Another transaction added new rows matching a predicate your transaction read. Applies to both WriteSerializable and Serializable isolation. |
| Metadata conflicts     | Another transaction changed table schema or properties.                                                                                      |

For more details about isolation levels and conflict resolution for transactions, see [Transaction modes](https://docs.databricks.com/aws/en/transactions/transaction-modes.md). For information about isolation levels and write conflict behavior for Delta Lake tables on Databricks, see [Optimization recommendations on Databricks](https://docs.databricks.com/aws/en/optimizations/index.md).

## <a id="history" />How transactions appear in the Delta log

Each successful transaction appears as a single entry in the table's Delta log, regardless of how many individual statements ran within the transaction. This allows for a clean audit trail and simplifies rollback operations.

Individual operations within a transaction are available as JSON metadata in the Delta log entry for the transaction.

## <a id="error-handling" />Error handling and rollback

The following table describes how error rollbacks occur for both transaction types:

| Scenario                                  | Behavior for non-interactive transactions                                                                                                                | Behavior for interactive transactions                                                                                                                                                                                                                                                                                                                                                                                          |
| ----------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Statement failure                         | Any statement that raises an error causes immediate automatic rollback.                                                                                  | You must explicitly run [ROLLBACK](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-txn-rollback.md) to discard changes if the session is still active.                                                                                                                                                                                                                                                   |
| Failed validation logic or business rules | Use [`SIGNAL`](https://docs.databricks.com/aws/en/sql/language-manual/control-flow/signal-stmt.md) to throw an exception and trigger automatic rollback. | Run [ROLLBACK](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-txn-rollback.md) to discard changes.                                                                                                                                                                                                                                                                                                      |
| Session disconnect                        | The transaction automatically rolls back.                                                                                                                | The transaction automatically rolls back.                                                                                                                                                                                                                                                                                                                                                                                      |
| Timeout                                   | Automatically rolls back after 48 hours total duration.                                                                                                  | Automatically rolls back after 10 minutes of inactivity or 48 hours total duration (see [Limitations](https://docs.databricks.com/aws/en/transactions/index.md#limitations)). The transaction is terminated without side effects, but you must explicitly run [ROLLBACK](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-txn-rollback.md) to clear the transaction state if the session is still active. |

For interactive transactions, you can explicitly roll back using the [ROLLBACK](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-txn-rollback.md) statement. This allows you to discard changes based on validation logic or business rules, or after a statement failure when the session remains active.

## <a id="best-practices" />Best practices

Follow these practices to reduce conflicts and optimize transaction performance.

### Avoid conflicts

* **Keep transactions short**: Long-running transactions increase conflict likelihood and hold resources longer.
* **Validate early**: Check preconditions at the beginning of a transaction to fail fast.
* **Use `BEGIN ATOMIC` for row-level concurrency**: Non-interactive transactions (`BEGIN ATOMIC ... END;`) detect conflicts at the row level, which reduces conflicts compared to the table-level detection that interactive transactions use. See [Non-interactive transactions](https://docs.databricks.com/aws/en/transactions/transaction-modes.md#non-interactive).
* **Build retry logic**: A transaction can fail at any time because of a conflict. Build retry logic into your application and retry failed transactions with fresh data.
* **Start each interactive session with a rollback**: Run [ROLLBACK](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-txn-rollback.md) at the start of an interactive session to clear any preexisting transaction state.

## <a id="client-implementations" />Use transactions from different clients

Transactions work across various client interfaces:

* **SQL Editor and notebooks**: Use [`BEGIN ATOMIC ... END;`](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-txn-begin-atomic.md) or [`BEGIN TRANSACTION; ... COMMIT;`](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-txn-begin.md) syntax directly in SQL cells or use `spark.sql()` in Python/Scala notebooks. See [Transaction modes](https://docs.databricks.com/aws/en/transactions/transaction-modes.md).
* **JDBC applications**: Use JDBC API methods (`setAutoCommit(false)`, `commit()`, `rollback()`) with the [Databricks JDBC driver](https://github.com/databricks/databricks-jdbc/releases) version 3.0.5 and above. See [Example: Use transactions](https://docs.databricks.com/aws/en/integrations/jdbc-oss/example.md#transactions). For a list of unsupported JDBC operations within transactions, see [Unsupported JDBC operations](https://docs.databricks.com/aws/en/transactions/transaction-modes.md#int-jdbc-not-supported).
* **ODBC applications**: Use the [Databricks ODBC Driver](https://docs.databricks.com/aws/en/integrations/odbc/index.md) version 2.10.0 and above. For a list of unsupported ODBC operations within transactions, see [Unsupported ODBC operations](https://docs.databricks.com/aws/en/transactions/transaction-modes.md#int-odbc-not-supported).
* **Python applications**: Use the Databricks SQL Connector with `autocommit=False`. See [Databricks SQL Connector for Python](https://docs.databricks.com/aws/en/dev-tools/python-sql-connector.md). For a list of unsupported Python connector operations within transactions, see [Unsupported Python connector operations](https://docs.databricks.com/aws/en/transactions/transaction-modes.md#int-python-not-supported).
* **Statement Execution API**: Run transactions using SQL syntax through API calls. See [Use with Statement Execution API](https://docs.databricks.com/aws/en/transactions/transaction-modes.md#ni-api).

## <a id="limitations" />Limitations

The following limitations apply to transactions:

| Limitation                                 | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| ------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Interactive transaction conflicts          | Interactive transactions ([BEGIN TRANSACTION](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-txn-begin.md); ... [COMMIT](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-txn-commit.md);) use more conservative conflict detection than non-interactive transactions and can conflict at the table level, except for INSERT operations that do not read from the target table. Use non-interactive transactions ([ATOMIC compound statement](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-txn-begin-atomic.md)) when row-level conflict detection is important. See [Non-interactive transactions](https://docs.databricks.com/aws/en/transactions/transaction-modes.md#non-interactive). |
| Write targets                              | You can only write to Unity Catalog managed Delta or Iceberg tables that have the `catalogManaged` table feature enabled. See [Catalog commits](https://docs.databricks.com/aws/en/tables/features/catalog-commits.md).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| DDL operations not supported               | Run DDL operations, such as `CREATE TABLE`, `ALTER TABLE`, or `DROP TABLE`, outside of transactions. For the operations that transactions support, see [Supported operations](https://docs.databricks.com/aws/en/transactions/index.md#supported-operations).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| Some metadata operations not supported     | Some metadata operations do not work inside transactions regardless of protocol. This includes Thrift RPC-based metadata calls (such as JDBC `DatabaseMetaData` methods and ODBC catalog functions), SQL-based commands that enumerate objects (such as `SHOW TABLES` and `SHOW DATABASES`), and `SELECT` queries against system tables. Run these metadata operations outside of transactions.                                                                                                                                                                                                                                                                                                                                                                 |
| `COPY INTO` concurrency                    | A transaction running a `COPY INTO` command fails if another `COPY INTO` command runs concurrently to write to the same table and commits first.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| Row-level concurrency for `MERGE`          | Row-level concurrency for `MERGE` operations is not supported on AWS GovCloud or on single-user (dedicated) clusters. On these platforms, `MERGE` operations use table-level concurrency. See [Row-level concurrency](https://docs.databricks.com/aws/en/optimizations/isolation/row-level-concurrency.md).                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| Table and view limits                      | A transaction can read from or write to up to 100 tables combined, and can read from up to 100 views. Each table can have up to 100 intermediate commits within a transaction.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| Time travel not supported                  | You cannot use [time travel](https://docs.databricks.com/aws/en/tables/history.md) within a transaction.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| Idle timeout                               | Interactive transactions roll back after 10 minutes of inactivity. The transaction is terminated without side effects, but you must explicitly run [ROLLBACK](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-txn-rollback.md) to clear the transaction state if the session is still active.                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| Lineage                                    | Transactions emit [lineage](https://docs.databricks.com/aws/en/data-governance/unity-catalog/data-lineage.md) as each read and write occurs. Lineage events persist even if the transaction is rolled back.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| Maximum duration                           | All transactions automatically roll back after 48 hours total duration. For interactive transactions, the transaction is terminated without side effects, but you must explicitly run [ROLLBACK](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-txn-rollback.md) to clear the transaction state if the session is still active.                                                                                                                                                                                                                                                                                                                                                                                                          |
| OpenSharing shared tables requirement      | OpenSharing providers must [share a table `WITH HISTORY`](https://docs.databricks.com/aws/en/opensharing/create-share.md#add-tables) to allow recipients to run transactions on it. Recipients can run transactions using any type of compute.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| OpenSharing recipient compute restrictions | Databricks recipients can only run transactions on shared views, materialized views, streaming tables, and non-Iceberg foreign tables. Recipients in the same Databricks account as their provider must use shared or serverless compute. Recipients in a different account must use serverless compute.                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| OpenSharing source table conflict          | OpenSharing recipients cannot reference a shared view and a shared table that reference the same source table within a single transaction.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |

## <a id="additional-resources" /> Additional resources

* [Transaction modes](https://docs.databricks.com/aws/en/transactions/transaction-modes.md)
* [Tutorial: Coordinate transactions across tables](https://docs.databricks.com/aws/en/transactions/tutorial.md)
* [Catalog commits](https://docs.databricks.com/aws/en/tables/features/catalog-commits.md)
* [Isolation levels and write conflicts](https://docs.databricks.com/aws/en/optimizations/isolation/index.md)
* [`ATOMIC` compound statement (non-interactive transactions)](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-txn-begin-atomic.md)
* [BEGIN TRANSACTION (interactive transactions)](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-txn-begin.md)
* [COMMIT](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-txn-commit.md)
* [ROLLBACK](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-txn-rollback.md)
