I am working on an Oracle sql database.
I have a stored procedure where I need to update the value of the primary key in a table.
That value is referenced by a foreign key from another table.
I can disable that foreign key constraint,then perform the update and then enable it back and this works.
The problem is that if something goes wrong after altering the foreign key status I cannot rollback prior to the update.
To resume:
- UPDATE
- ALTER FOREIGN KEY
- ROLLBACK
Is there any way I can rollback to the state before performing the update and if yes then how ?
Thanks.
Unfortunately not. ALTER TABLE is a DDL command, and DDL statements cannot be
ROLLBACKed. So you cannot rollback before this command.Solution for you could be to change foreign key to deffered validation. You can then change the primary key and foreign key using two updates in ona transaction. Constraint will be validated at next commit.