有时在删除某一表时发现有外键约束不能删除,隐藏需要先删除外键对应的表,以下便是查询的sql:
select pk.owner,pk.table_name, pk.constraint_type,pk.constraint_name, fk.owner,fk.table_name,fk.constraint_name,fk.constraint_type from dba_constraints pk , dba_constraints fk where pk.constraint_type='P' and pk.constraint_name=fk.r_constraint_name and fk.constraint_type='R' and fk.constraint_name like '%228D5152%'--外键名称
select a.table_name 外键表名,a.column_name 外键列名,b.table_name 主键表名,b.column_name 主键列名 from (select a.constraint_name,b.table_name,b.column_name,a.r_constraint_name from user_constraints a, user_cons_columns b WHERE a.constraint_type='R' and a.constraint_name=b.constraint_name ) a, (select distinct a.r_constraint_name,b.table_name,b.column_name from user_constraints a, user_cons_columns b WHERE a.constraint_type='R' and a.r_constraint_name=b.constraint_name) b where a.r_constraint_name=b.r_constraint_name;