disable enable 所有其他表关联的外键

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;

猜你喜欢

转载自www.cnblogs.com/kakaisgood/p/9068813.html