1.检查哪些表的外键引用了要删除的表的唯一/主键.
select A.*
from user_constraints A, user_constraints B
WHERE b.table_name = 'MYTEST'
and a.constraint_type = 'R'
and a.r_constraint_name = b.constraint_name;
2.生成所有引用要删除表的外键的创建语句.
select 'select dbms_metadata.get_ddl(''REF_CONSTRAINT'',''' ||
A.CONSTRAINT_NAME || ''') FROM DUAL;'
from user_constraints A, user_constraints B
WHERE b.table_name = 'MYTEST'
and a.constraint_type = 'R'
and a.r_constraint_name = b.constraint_name;
3.执行步骤2中产生的SQL语句,获取外键定义.
set long 3000
set linesize 3000
set pagesize 300
执行步骤2产生的语句.
4.删除表.
drop table mytest cascade constraints;
5.删除并重建表.
6.建立因创建该表所删除的外键约束.
执行步骤3中获取到的sql语句.
7.检查各外键是否得到恢复,系统是否正常.