Friday 18 February 2011

DDL Rollback in Oracle...

Oracle does not support DDL Rollback, Try the following example:

CREATE TABLE FOO(
FOO_ID NUMBER,
FOO_NAME VARCHAR2(30)
);
ALTER TABLE FOO ADD FOO_DESCRIPTION VARCHAR2(50);
INSERT INTO FOO VALUES (1,'FIRST','THE FIRST ROW');
INSERT INTO FOO VALUES (2,'SECOND','THE SECOND ROW');

SELECT * FROM FOO;
ROLLBACK;
SELECT * FROM FOO;

Does rollback statement drops the table created as well? or undo the alter statement?

It only undo the Insert which is a DML, it can not rollbacl DDL statements.

There are two work arounds of this problem:

1. Using Oracle Flachback utility.
Problem with this solution is it has a lot of management overhead and does not work on statement level. This tool can rollback the whole table but can not rollback a simgle alter statement.

2. Database Change Management tools like dbdeploy & mybatis.
This tool can do it all and with quite good flexibility. However, if you already have a database and big tables and we want to drop the tables. In this case we will have to right large insert statements to undo the change.

3. Using both.
Looking at the shortcomings of the above two approaches, i would recommend using this approach.

No comments:

Post a Comment

Azure OpenAI Architecture Patterns & Deployment Patterns

Sharing some useful links that will help customers architect Azure OpenAI solution using the best practices: (1) Azure OpenAI Landing Zone r...