views:

422

answers:

2

I've got a program that periodically updates its database schema. Sometimes, one of the DDL statements might fail and if it does, I want to roll back all the changes. I wrap the update in a transaction like so:

BEGIN TRAN;

CREATE TABLE A (PKey int NOT NULL IDENTITY, NewFieldKey int NULL, CONSTRAINT PK_A PRIMARY KEY (PKey));
CREATE INDEX A_2 ON A (NewFieldKey);
CREATE TABLE B (PKey int NOT NULL IDENTITY, CONSTRAINT PK_B PRIMARY KEY (PKey));
ALTER TABLE A ADD CONSTRAINT FK_B_A FOREIGN KEY (NewFieldKey) REFERENCES B (PKey);

COMMIT TRAN;

As we're executing, if one of the statements fail, I do a ROLLBACK instead of a COMMIT. This works great on SQL Server, but doesn't have the desired effect on Oracle. Oracle seems to do an implicit COMMIT after each DDL statement:

Is there any way to turn off this implicit commit?

+5  A: 

You can not turn this off. Fairly easy to work around by designing your scripts to drop tables in the event they already exist etc...

You can look at using FLASHBACK database, I believe you can do this at the schema/object level but check the docs to confirm that. You would need to be on 10G for that to work.

Ethan Post
A: 

Thanks, Ethan. Not the answer I wanted, but still what I expected.

I was hoping not to have to add any pre-flight validation considering everything rolls back fine on SQL Server, but it looks like I don't have a choice.

Chris Karcher