Oracle查出所有主表或从表


--查出所有从表
select
/*+ INDEX(sys.con$,I_CON1) */
OWNER
,CONSTRAINT_NAME
,CONSTRAINT_TYPE
,TABLE_NAME
,R_OWNER
,R_CONSTRAINT_NAME
  from ALL_CONSTRAINTS T
where T.OWNER = SYS.LOGIN_USER
   and T.CONSTRAINT_TYPE = 'R'
   and T.R_CONSTRAINT_NAME in
       (select CONSTRAINT_NAME
          from ALL_CONSTRAINTS
         where CONSTRAINT_TYPE in ('P', 'U')
         and TABLE_NAME = 'MESSAGE');

--查出所有主表         
  select
  /*+ INDEX(sys.con$,I_CON1) */
   OWNER
  ,CONSTRAINT_NAME
  ,CONSTRAINT_TYPE
  ,TABLE_NAME
  ,R_OWNER
  ,R_CONSTRAINT_NAME
    from ALL_CONSTRAINTS T
   where T.OWNER = user
     and T.CONSTRAINT_TYPE in ('P', 'U')
     and T.CONSTRAINT_NAME in
         (select ALL_CONS.R_CONSTRAINT_NAME
            from SYS.ALL_CONSTRAINTS ALL_CONS
           where ALL_CONS.CONSTRAINT_TYPE in ('R', 'U')
             and ALL_CONS.TABLE_NAME = 'MODEL_FILE');

你可能感兴趣的:(oracle)