Search code examples
oracletransactionsddl

Oracle: DDL and transaction rollback


Could in Oracle DDL (create/alter) be transactional like they are in MS SQL (started from 2005)?


Solution

  • No. In Oracle DDL statements themselves are not transactional, or rather, each DDL statement includes an implicit commit before and after the statement.

    Any data modifications that are part of that statement are done within that transaction. For example, certain alter table statements may fire triggers on the table, which in turn can do other DML. All of that will run in the transaction that embeds the DDL statement, and if the DDL statement would fail or is cancelled, all of it will be rolled back.

    But you can't start an explicit transaction to roll back multiple DDL statements (yet).

    In addition some statements, like an alter table statement, may fail if another session has an open transaction on the object being modified or one of its dependencies. You can set a ddl_lock_timeout to specify how long you want Oracle to wait for the object to become available.

    See DDL Statements for a summary of types of DDL statements and information about their behaviour regarding locks and transactions.

    Oracle Database implicitly commits the current transaction before and after every DDL statement.