Tuesday, September 29, 2009

Script to disable All Constraints

declare
Cursor cCons is select table_name,constraint_name
from user_constraints
where status = 'ENABLED'
order by decode(constraint_type,'R','A',constraint_type);
type t is table of cCons%rowtype index by binary_integer;
all_constraints t;

nLimit int := 100;
begin

open cCons;
loop
Fetch cCons Bulk Collect into all_constraints limit nLimit;

for i in 1..all_constraints.count loop
begin
execute immediate 'Alter table '||all_constraints(i).table_name||' disable constraint '|| all_constraints(i).constraint_name;
Exception
WHEN Others then
null; -- to ignore any system generated constriants for BLOB/CLOB columns
end;
end loop;

exit when all_constraints.count < nLimit;
end loop;
Close cCons;

end;
/

No comments:

Post a Comment