---
title: BEGIN TRANSACTION
description: Begin an interactive transaction that groups multiple SQL statements into one unit of work with BEGIN TRANSACTION in Databricks SQL.
canonical_url: https://docs.databricks.com/gcp/en/sql/language-manual/sql-ref-syntax-txn-begin
---

# BEGIN TRANSACTION

**Applies to:** ![check marked yes](https://docs.databricks.com/gcp/en/images/icons/check.png) Databricks SQL

Begins a new interactive transaction that groups multiple SQL statements into a single unit of work that can be committed or rolled back.

As an alternative to interactive transactions, you can define non-interactive transactions using the `BEGIN ATOMIC ... END;` syntax. See [ATOMIC compound statement](https://docs.databricks.com/gcp/en/sql/language-manual/sql-ref-syntax-txn-begin-atomic.md).

## Syntax

```
BEGIN { TRANSACTION | WORK }
```

## Parameters

This statement has no parameters.

## Notes

* If an interactive transaction is already active, executing `BEGIN TRANSACTION` again results in a [TRANSACTION\_NOT\_SUPPORTED.NESTED\_TRANSACTION](https://docs.databricks.com/gcp/en/error-messages/transaction-not-supported-error-class.md) error. Interactive transactions do not support nesting.
* `BEGIN TRANSACTION` and `BEGIN WORK` are equivalent syntax alternatives.

## Examples

The following examples demonstrate common interactive transaction patterns.

### Basic cross-table transaction

Run each statement separately.

```sql
BEGIN TRANSACTION;
```

```sql
-- Insert a new record
INSERT INTO my_table VALUES (1, 'test');
```

```sql
-- Update records in another table
UPDATE another_table
SET value = 'updated'
WHERE id = 5;
```

```sql
-- Commit all changes in both tables atomically
COMMIT TRANSACTION;
```

### Read-your-own-writes

Run each statement separately.

```sql
BEGIN TRANSACTION;
```

```sql
-- Insert new data
INSERT INTO customers VALUES (101, 'New Customer');
```

```sql
-- Query can see the inserted data within the same transaction
SELECT * FROM customers WHERE id = 101;
-- Returns the newly inserted row even though it's not yet committed
```

```sql
-- Update the newly inserted data
UPDATE customers SET name = 'Updated Customer Name' WHERE id = 101;
```

```sql
-- Query sees the updated value
SELECT name FROM customers WHERE id = 101;
-- Returns 'Updated Customer Name'
```

```sql
-- Commit makes changes visible to other transactions
COMMIT TRANSACTION;
```

### Transaction with rollback

Run each statement separately.

```sql
BEGIN TRANSACTION;
```

```sql
-- Attempt an insert operation
INSERT INTO my_table VALUES (1, 'incorrect-value');
```

```sql
-- After discovering the mistake, rollback the transaction
-- (no changes are actually made to the tables)
ROLLBACK TRANSACTION;
```

### Visibility of uncommitted changes

In this example, changes within a transaction are not visible to other sessions until the transaction is committed. Run each statement separately.

**Session 1:**

```sql
BEGIN TRANSACTION;
```

```sql
-- Insert new data
INSERT INTO products VALUES (999, 'New Product', 29.99);
```

```sql
-- At this point, Session 2 cannot see this data
-- You can see your own changes
SELECT * FROM products WHERE id = 999;
-- Returns the new product
```

**Session 2 (concurrent):**

```sql
-- This query does not see the uncommitted data from Session 1
SELECT * FROM products WHERE id = 999;
-- Returns no rows
```

**Session 1 (continued):**

```sql
-- Now commit the transaction
COMMIT TRANSACTION;
```

**Session 2 (after commit):**

```sql
-- Now the query can see the committed data
SELECT * FROM products WHERE id = 999;
-- Returns the new product
```

### Visibility of concurrent changes

In this example, concurrent changes made outside the transaction are not visible to the transaction. Databricks captures a consistent snapshot of each table at first access, and all subsequent reads of that table use this snapshot (repeatable read). Run each statement separately.

**Session 1** (start a transaction and read the table):

```sql
BEGIN TRANSACTION;
```

```sql
-- Read the table; captures a snapshot of orders at this point
SELECT COUNT(*) FROM orders;
-- Returns: 1
```

**Session 2** (concurrent session adds a row):

```sql
INSERT INTO orders VALUES (2, 'Product B', 75.00);
COMMIT;
```

**Session 1** (continued, re-read the table):

```sql
-- Still reads from the original snapshot; the new row is not visible
SELECT COUNT(*) FROM orders;
-- Returns: 1 (unchanged, even though Session 2 committed a new row)
```

```sql
COMMIT;
```

This guarantees consistent reads throughout the transaction, regardless of concurrent modifications.

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

* [ATOMIC compound statement (non-interactive transactions)](https://docs.databricks.com/gcp/en/sql/language-manual/sql-ref-syntax-txn-begin-atomic.md): Run multiple SQL statements as a single atomic transaction with automatic commit and rollback
* [COMMIT](https://docs.databricks.com/gcp/en/sql/language-manual/sql-ref-syntax-txn-commit.md): Commit an interactive transaction and make all changes permanent
* [ROLLBACK](https://docs.databricks.com/gcp/en/sql/language-manual/sql-ref-syntax-txn-rollback.md): Roll back an interactive transaction and discard all changes
* [Transactions](https://docs.databricks.com/gcp/en/transactions/index.md): Overview of transaction support, requirements, and limitations
* [Transaction modes](https://docs.databricks.com/gcp/en/transactions/transaction-modes.md): Detailed patterns and examples for non-interactive and interactive transactions
* [BEGIN END compound statement](https://docs.databricks.com/gcp/en/sql/language-manual/control-flow/compound-stmt.md): `BEGIN ... END` blocks without the `ATOMIC` keyword
