Query to search for table relationship types

Using Oracle, is it possible to somehow execute a query to determine what relationship a particular table has with any other tables in my database? I am playing with a table now all_constraints.

+3
source share
2 answers

Yes, you can do this, for example:

select p.table_name, 'is parent of ' rel, c.table_name
from   user_constraints p
join   user_constraints c on c.r_constraint_name = p.constraint_name
                         and c.r_owner = p.owner
where p.table_name = 'MYTABLE'    
union all
select c.table_name, 'is child of ' rel, p.table_name
from   user_constraints p
join   user_constraints c on c.r_constraint_name = p.constraint_name
                         and c.r_owner = p.owner
where c.table_name = 'MYTABLE' 
+6
source

I think your best bet is trying to extract as much information as possible from foreign key constraints .

Have a look in this article in the database log, which details mining of foreign key data.

+3
source

Source: https://habr.com/ru/post/1761517/


All Articles