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
http://publib.boulder.ibm.com/infocenter/db2luw/v9r5/topic/com.ibm.db2.luw.sql.ref.doc/doc/r0000972.htmlan
d then run the ALTER TABLE table-name DROP FOREIGN KEY and ALTER
TABLE table-name ADD FOREIGN KEY commands
http://publib.boulder.ibm.com/infocenter/db2luw/v9r5/topic/com.ibm.db2.luw.sql.ref.doc/doc/r0000888.htmlThin
gs 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