DBA FUS‎ > ‎

Finding unindexed fkeys

posted Sep 13, 2010, 7:45 AM by Sachchida Ojha
SELECT t.owner,
       t.table_name primary_table,
       c.constraint_name,
       c.table_name second_table,
       acc.column_name
FROM   all_constraints t,
       all_constraints c,
       all_cons_columns acc
WHERE  c.r_constraint_name = t.constraint_name
AND    c.table_name        = acc.table_name
AND    c.constraint_name   = acc.constraint_name
AND    t.owner not in ('SYS', 'SYSTEM','MDSYS','SYSMAN','DBSNMP','OLAPSYS','EXFSYS')
AND    NOT EXISTS (SELECT '1'
                   FROM  all_ind_columns aid
                   WHERE aid.table_name  = acc.table_name
                   AND   aid.column_name = acc.column_name)
ORDER BY c.table_name;
Comments