[Oracle] İlişkili tabloları bulma

Aşağıdaki script ile birbiri ile arasında ilişki bulunan tabloları bulabilirsiniz.

Constraint type’ların karşılıkları :
C – Check constraint on a table
P – Primary key
U – Unique key
R – Referential integrity
V – With check option, on a view
O – With read only, on a view
H – Hash expression
F – Constraint that involves a REF column
S – Supplemental logging

select uc.constraint_name as TableConstraint1,
uc.r_constraint_name as TableConstraint2,
uc.table_name as Table1,
us.table_name as Table2,
ucc.column_name as TableColumn1,
uccs.column_name as TableColumn2
from user_constraints uc
inner join user_constraints us on
uc.r_constraint_name = us.constraint_name
inner join USER_CONS_COLUMNS ucc on
ucc.constraint_name = uc.constraint_name
inner join USER_CONS_COLUMNS uccs on
uccs.constraint_name = us.constraint_name
where us.constraint_type in ('P','U');

kaynak : http://stackoverflow.com/questions/183642/what-do-the-letter-codes-in-oracle-user-contraints-tables-constraint-type-colum

kaynak : http://stackoverflow.com/questions/85978/query-a-tables-foreign-key-relationships

Bir Cevap Yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir