比如:a表和b表通过一个外键关联起来,此时怎么知道a和其他表(如b表)有关联?

解决方案 »

  1.   

    select * from user_cons_columns cl where cl.table_name = 'A' and cl.column_name = '外键名'
      

  2.   


    -- 查询被指定表引用的父表
    select
    c.owner||'.'||c.table_name child_table,
    c.constraint_name,
    r.owner||'.'||r.table_name parent_table
    from dba_constraints c,dba_constraints r
    where c.owner=r.r_owner and c.constraint_name=r.r_constraint_name
    and c.owner=upper('&child_owner') and c.table_name=upper('&child_table');-- 查询引用指定表的子表
    select
    c.owner||'.'||c.table_name child_table,
    c.constraint_name,
    r.owner||'.'||r.table_name parent_table
    from dba_constraints c,dba_constraints r
    where c.owner=r.r_owner and c.constraint_name=r.r_constraint_name
    and r.owner=upper('&parent_owner') and r.table_name=upper('&parent_table');