oracle查看所有表的主外键关系

select
pk_table 主键表,
pk_col 主键表ID,
fk_table 外键表,
fk_col 外键表ID,
pk_con constraint_name,
del_rule dellete_rule
from
(select
a.constraint_name pk_con,
a.table_name pk_table,b.column_name pk_col,
a.owner pk_owner
from user_constraints a,user_cons_columns b
where (a.constraint_type='P' or a.constraint_type='U')
and a.constraint_name=b.constraint_name
and a.owner=b.owner) pk,
(select c.constraint_name fk_con,
c.table_name fk_table,
c.delete_rule del_rule,
d.column_name fk_col,
c.R_OWNER r_pk_owner,
c.R_CONSTRAINT_NAME r_pk_con,
c.owner fk_owner
from user_constraints c,user_cons_columns d
where c.constraint_type='R'
and c.constraint_name=d.constraint_name
and c.owner=d.owner) fk
where pk.pk_owner=fk.r_pk_owner
and pk.pk_con=fk.r_pk_con
order by pk.pk_con;


select a.constraint_name,a.delete_rule from user_constraints a where a.delete_rule='NO ACTION' or a.delete_rule='CASCADE' or a.delete_rule='SET NULL';

你可能感兴趣的:(oracle)