Tuesday, November 17, 2009

How to disable and reenable constraints in Oracle

Disable
1. Run this script in your sql editor and output the results

select 'ALTER TABLE '||substr(c.table_name,1,35)||
' DISABLE CONSTRAINT '||constraint_name||' CASCADE;'
from user_constraints c, user_tables u
where c.table_name = u.table_name;

2. Copy paste the results and run them in your SQL editor again


Enable
1. Run this script in your sql editor and output the results

select 'ALTER TABLE '||substr(c.table_name,1,35)||
' ENABLE CONSTRAINT '||constraint_name||' ;'
from user_constraints c, user_tables u
where c.table_name = u.table_name;

2. Copy paste the results and run them in your SQL editor again