Question : Alter Table Alter Constraint

Hi All,
I want to alter Foreigh Key without dropping it, is it possible to do so..
Currently FK is with On Delete Restrict , I want to alter it for On Delete Cascade.

FK Def:-
 REFERENCES "@[email protected]"."BNKPENDINGUSER"
 ON DELETE RESTRICT          <--------------------------- I want this as  ON DELETE CASCADE

Answer : Alter Table Alter Constraint

Based on your question, it seems you want to ensure that changes are not made to the table while the FK is being changed.  You could issue LOCK TABLE table-name EXCLUSIVE

and then run the ALTER TABLE table-name DROP FOREIGN KEY and ALTER TABLE table-name ADD FOREIGN KEY commands

Things to keep in mind with this approach:

The LOCK TABLE command will hold the lock until a COMMIT is issued.  Therefore you need to ensure that AUTO-COMMIT is OFF when attempting this process.

The ALTER TABLE ADD FOREIGN KEY will need to validate the data in the tables involved.  This could take some time depending on the amount of data in the tables referenced by the FK.  This means that the table could be locked for a long period of time.  Ensure that you discuss this with the users of this table and acquire the necessary outage time required to make this change.

- Greg
Random Solutions  
programming4us programming4us