ROLLBACK
without a savepoint qualifier will roll back the entire current transaction.
For DDL statements, there is no current transaction to rollback. The DDL statement implicitly generates a COMMIT
before the statement starts and after it completes. So if you issue a ROLLBACK
following a DROP
, no work has been done in the current transaction so there is nothing to roll back.
For DML statements, you'll roll back the entire current transaction. If you do
your transaction begins when you execute the INSERT
operation. So when you issue the ROLLBACK
, you are rolling back both the INSERT
and the DELETE
so you're back to having no data in the table (assuming you started with no data). If you COMMIT
after the INSERT
then the next transaction would begin with the DELETE
and your ROLLBACK
will only roll back the DELETE
operation. Alternately, you can declare a savepoint after the INSERT
and roll back to the savepoint
SQL> create table foo( col1 number );
Table created.
SQL> insert into foo values( 1 );
1 row created.
SQL> savepoint after_insert;
Savepoint created.
SQL> delete from foo;
1 row deleted.
SQL> rollback to savepoint after_insert;
Rollback complete.
SQL> select * from foo;
COL1
----------
1