Reputation: 4677
Suppose, on the SQL prompt in Oracle 9i, I'm creating a simple table say orderStatus with only two columns with the following CREATE SQL command.
CREATE TABLE orderStatus(statusID varchar2(6) primary key, status varchar2(15));
just then I'm entering four rows with the following INSERT INTO commands.
INSERT INTO orderStatus VALUES("S0001", "Fulfilled");
INSERT INTO orderStatus VALUES("S0002", "Back order");
INSERT INTO orderStatus VALUES("S0003", "In process");
INSERT INTO orderStatus VALUES("S0004", "Cancelled");
On successful execution of the above commands, I'm issuing a COMMIT command to complete the current transaction.
COMMIT;
just then I need to fire the following DELETE command.
DELETE FROM orderStatus WHERE statusID="S0004";
which deletes one row with the statusID S0004. The table now contains only 3 rows.
Suppose, I need to add the NOT NULL constraint to the status column which requires the following ALTER TABLE command.
ALTER TABLE orderStatus MODIFY(status varchar(15) NOT NULL);
The table orderStatus will be altered to add a NOT NULL constraint to the status column.
Now, suppose I execute a ROLLBACK command on the SQL prompt which causes the current transaction to finish with all the data which are previously affected in this table to be undone. With this, the previously deleted row with the DELETE command above should be undone and the table should now contain the original four rows but the effect of ROLLBACK can not be observed and the table would have only three rows. Why does this happen?
Upvotes: 0
Views: 180
Reputation: 231851
DDL (CREATE TABLE
and ALTER TABLE
, for example) issues an implicit commit before the statement is executed and after the statement completes. You cannot roll back DDL and you cannot roll back DML changes (like your DELETE
) after the implicit commits your DDL causes.
This is why you do not generally want to mix DDL and DML.
Upvotes: 4