Disable:

begin

for i in (select constraint_name, table_name from user_constraints where constraint_name in (select fk_col.constraint_name

from user_constraints pk, user_constraints fk, user_cons_columns fk_col

where pk.table_name = '表名'

and pk.constraint_type = 'P'

and fk.r_constraint_name = pk.constraint_name

and fk_col.constraint_name = fk.constraint_name)) LOOP

execute immediate 'alter table '||i.table_name||' disable constraint '||i.constraint_name||'';

end loop;

end;

enable:

begin

for i in (select constraint_name, table_name from user_constraints where constraint_name in (select fk_col.constraint_name

from user_constraints pk, user_constraints fk, user_cons_columns fk_col

where pk.table_name = '表名'

and pk.constraint_type = 'P'

and fk.r_constraint_name = pk.constraint_name

and fk_col.constraint_name = fk.constraint_name)) LOOP

execute immediate 'alter table '||i.table_name||' enable constraint '||i.constraint_name||'';

end loop;

end;

/

COMMIT;

05-13 15:19