GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Tech FAQs  >  Oracle
Go To First  |  Previous Question  |  Next Question 
 Oracle  |  Question 163 of 244    Print  
How to find the Foreign keys of all child tables when pass the Parent Table name.
I developed like below.Any experts query ....please send.

select
table_name,constraint_name
from user_cons_columns where column_name=(
select a.COLUMN_NAME from user_cons_columns a,user_constraints b
where a.TABLE_NAME=b.TABLE_NAME
and b.constraint_type in ('P')
and a.TABLE_NAME='DEPT')
and constraint_name like '%FK%'



  
Total Answers and Comments: 3 Last Update: August 19, 2009     Asked by: sheker2007 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
December 12, 2007 02:19:21   #1  
kishore.giri Member Since: December 2007   Contribution: 15    

RE: How to find the Foreign keys of all child tables when pass the Parent Table name.

MY DEAR

PLZ QUERY THE DATA DICTIONARY VIEW CALLED 'USER_DEPENDENCIES' AND PASS YOUR PARENT TABLENAME IN THE NAME COLUMN AND ALSO GIVE THE TYPE TABLE IN THE WHERE CLAUSE OF QUERY.

PLZ TRY IT AND REPLY.


REGARDS
Kishore Kumar Giri


 
Is this answer useful? Yes | No
May 13, 2008 04:43:07   #2  
Imran_Javed Member Since: May 2008   Contribution: 23    

RE: How to find the Foreign keys of all child tables when pass the Parent Table name.
SELECT
uc.CONSTRAINT_NAME
ut.TABLE_NAME
ucc.COLUMN_NAME
FROM
USER_CONS_COLUMNS ucc
USER_CONSTRAINTS uc
USER_TABLES ut
WHERE
uc.table_name ut.TABLE_NAME AND
uc.CONSTRAINT_NAME ucc.CONSTRAINT_NAME AND
uc.CONSTRAINT_TYPE 'R' AND
ut.table_name 'DEPT';

 
Is this answer useful? Yes | No
August 18, 2009 07:20:43   #3  
sen_sam86 Member Since: June 2008   Contribution: 10    

RE: How to find the Foreign keys of all child tables when pass the Parent Table name.
Try this script

Example


SELECT child.table_name AS TABL_NAME_2
'Is Parent Of' AS RELATION
parent.table_name AS TABL_NAME_1
UCC.column_name AS COL_NAME
parent.constraint_name AS CONSTRNT_NAME
DECODE (parent.constraint_type 'P' 'Primary Key' 'R' 'Foreign Key') AS CONSTRNT_TYPE
FROM user_constraints parent
user_constraints child
user_cons_columns UCC
WHERE parent.r_constraint_name child.constraint_name
AND parent.r_owner child.owner
AND child.table_name v_tab_name
AND child.constraint_name ucc.constraint_name

UNION ALL

SELECT child.table_name AS TABL_NAME_2
'Is Child Of' AS RELATION
parent.table_name AS TABL_NAME_1
ucc.column_name AS COL_NAME
child.constraint_name AS CONSTRNT_NAME
DECODE (child.constraint_type 'P' 'Primary Key' 'R' 'Foreign Key') AS CONSTRNT_TYPE
FROM user_constraints child
user_constraints parent
user_cons_columns ucc
WHERE child.r_constraint_name parent.constraint_name
AND child.r_owner parent.owner
AND child.table_name v_tab_name
--and child.constraint_type in ('R')
AND child.constraint_name ucc.constraint_name


Hope it will help you



 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape