For a given table \'foo\', I need a query to generate a set of tables that have foreign keys that point to foo. I\'m using Oracle 10G.
The following statement should give the children and all of their descendents. I have tested it on an Oracle 10 database.
SELECT level, main.table_name parent,
link.table_name child
FROM user_constraints main, user_constraints link
WHERE main.constraint_type IN ('P', 'U')
AND link.r_constraint_name = main.constraint_name
START WITH main.table_name LIKE UPPER('&&table_name')
CONNECT BY main.table_name = PRIOR link.table_name
ORDER BY level, main.table_name, link.table_name