---
title: "Transactional DDL"
url: "https://docs.yugabyte.com/stable/explore/transactions/transactional-ddl/"
---

# Transactional DDL

Learn how to roll back DDL statements in a YugabyteDB transaction using transactional DDL.

Learn how to roll back DDL statements in a transaction

YugabyteDB can roll back DDL statements that run inside a transaction block. All DDLs supported in YugabyteDB provide the same rollback capabilities as PostgreSQL. These include DDLs on tables, indexes, roles, and materialized views.

For more information and current limitations, see [Transactional DDL](/stable/architecture/transactions/transactional-ddl/ "Transactional DDL").

## Roll back a DDL statement

Before you start

This example requires transactional DDL (disabled by default). Create and connect to a YugabyteDB universe, then enable `ysql_yb_ddl_transaction_block_enabled` as described in [Enable transactional DDL](/stable/architecture/transactions/transactional-ddl/#enable-transactional-ddl "Enable transactional DDL").

The following example shows an `ALTER TABLE` inside a transaction. The insert and the schema change commit together, or they both roll back.

```sql
yugabyte=# CREATE TABLE foo (bar int);
yugabyte=# INSERT INTO foo VALUES (1);
yugabyte=# BEGIN;
yugabyte=*# INSERT INTO foo VALUES (2);
yugabyte=*# ALTER TABLE foo ADD COLUMN name text;
yugabyte=*# INSERT INTO foo VALUES (3, 'test');
yugabyte=*# SELECT * FROM foo;
```

```output
 bar | name
-----+------
   1 |
   2 |
   3 | test
(3 rows)
```

```sql
yugabyte=*# ROLLBACK;
yugabyte=# SELECT * FROM foo;
```

```output
 bar
-----
   1
(1 row)
```

To speed up bulk loads into tables created in the same transaction, see [Faster writes to new tables](/stable/explore/transactions/new-table-writes/ "Faster writes to new tables"). That optimization's transaction-block support depends on transactional DDL.
