> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ocient.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Transactional Control Language (TCL) Statement Reference

export const Spark = "Apache® Spark™";

export const Ocient = "Ocient®";

The {Ocient} System supports multi-statement transactions. By default, a connection uses autocommit mode, in which the database commits each statement immediately. To group several statements into a single transaction, disable autocommit with [SET AUTOCOMMIT](#set-autocommit), and then end the transaction with [COMMIT](#commit) or [ROLLBACK](#rollback).

<Info>
  The HTTP Query API does not support transactions. To use transactions, connect to the Ocient System with the Ocient JDBC driver or the pyocient module.
</Info>

<Info>
  The {Spark} Connector supports transactions and performs the commit and rollback actions automatically. When you use the Spark Connector, you do not need to issue COMMIT or ROLLBACK statements.
</Info>

## SET AUTOCOMMIT

Enables or disables autocommit mode for the connection. When autocommit is enabled, the database commits each statement immediately. This mode is the default. When autocommit is disabled, the database groups subsequent statements into a transaction that you complete with the [COMMIT](#commit) or [ROLLBACK](#rollback) statements. Valid values are:

* `ON` — Enables autocommit mode, in which the database commits each statement immediately. This value is the default.
* `OFF` — Disables autocommit mode. The database groups subsequent statements into a transaction until you enter the COMMIT or ROLLBACK statement.

When you change autocommit from `OFF` to `ON`, the database commits any pending transactions.

After you disable autocommit, ensure that you execute SQL statements that are supported by transactions. Otherwise, the database throws an error. For a list of supported statements, see [Transactions](/transactions).

**Syntax**

```sql SQL theme={null}
SET AUTOCOMMIT { ON | OFF }
```

**Example**

This example disables autocommit, inserts two rows into a table, and then commits the transaction to permanently save the rows.

Disable autocommit.

```sql SQL theme={null}
SET AUTOCOMMIT OFF;
```

Create the public.txn\_demo table with two columns: a number and a string.

```sql SQL theme={null}
CREATE TABLE public.txn_demo (
    id INT,
    term VARCHAR(255));
```

Insert two rows into the `public.txn_demo` table and commit these two transactions.

```sql SQL theme={null}
INSERT INTO public.txn_demo VALUES (1, 'alpha');
INSERT INTO public.txn_demo VALUES (2, 'beta');
COMMIT;
```

Drop the table.

```sql SQL theme={null}
DROP TABLE public.txn_demo;
```

## COMMIT

Commits the current transaction and permanently saves all changes made after the transaction started. This statement applies only when you disable autocommit with [SET AUTOCOMMIT](#set-autocommit). When autocommit is enabled, COMMIT has no effect.

**Syntax**

```sql SQL theme={null}
COMMIT
```

**Example**

This example disables autocommit, inserts two rows into the `public.txn_demo` table, and then commits the transaction to permanently save the rows.

Disable the autocommit.

```sql SQL theme={null}
SET AUTOCOMMIT OFF;
```

Create the public.txn\_demo table with two columns: a number and a string.

```sql SQL theme={null}
CREATE TABLE public.txn_demo (
    id INT,
    term VARCHAR(255));
```

Insert two rows into the `public.txn_demo` table and commit these two transactions.

```sql SQL theme={null}
INSERT INTO public.txn_demo VALUES (1, 'alpha');
INSERT INTO public.txn_demo VALUES (2, 'beta');
COMMIT;
```

Drop the table.

```sql SQL theme={null}
DROP TABLE public.txn_demo;
```

## ROLLBACK

Rolls back the current transaction and discards all changes made after the transaction started. This statement applies only when you disable autocommit with [SET AUTOCOMMIT](#set-autocommit). When autocommit is enabled, ROLLBACK has no effect.

**Syntax**

```sql SQL theme={null}
ROLLBACK
```

**Example**

This example disables autocommit, inserts two rows in a table, and then rolls back the transaction to discard the inserted rows.

Disable the autocommit.

```sql SQL theme={null}
SET AUTOCOMMIT OFF;
```

Create the `public.txn_demo` table with two columns: a number and a string.

```sql SQL theme={null}
CREATE TABLE public.txn_demo (
    id INT,
    term VARCHAR(255));
```

Insert two rows into the `public.txn_demo` table, then roll back both transactions.

```sql SQL theme={null}
INSERT INTO public.txn_demo VALUES (3, 'gamma');
INSERT INTO public.txn_demo VALUES (4, 'delta');
ROLLBACK;
```

Drop the table.

```sql SQL theme={null}
DROP TABLE public.txn_demo;
```

## Related Links

[Data Manipulation Language (DML) Statement Reference](/data-manipulation-language-dml-statement-reference)

[Data Query Language (DQL) Statement Reference](/data-query-language-dql-statement-reference)

[Data Definition Language (DDL) Statement Reference](/data-definition-language-ddl-statement-reference)

[Commands Supported by the Ocient JDBC CLI Program](/commands-supported-by-the-ocient-jdbc-cli-program)

[Ocient Python Module (pyocient)](/ocient-python-module-pyocient)
