Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Foreign Keys

Status
Not open for further replies.

cpaige

Programmer
Jun 19, 2000
86
CA
Hey Guys!!
I have a problem. I want to find out what fields in different tables are foreign keys for a specific field.

Thanks! :^) Clayton T. Paige
claytonpaige@yahoo.ca

Programmer Extraordinaire

========================================================

"Who is General Failure? and Why is he reading my disk drive?"
 
You can use the following query:
(note : please substitute '&table_name' and '&column_name'
with the name of the primary key column, table respectively

-------------
select a.column_name, a.table_name
from sys.all_constraints c, sys.all_cons_columns a
where c.constraint_type ='R'
and c.constraint_name = a.constraint_name
and c.r_constraint_name = (
select d.constraint_name
from sys.all_constraints d, sys.all_cons_columns e
where d.constraint_name = e.constraint_name
and d.constraint_type ='P'
and e.table_name=upper('&table_name') and e.column_name =upper('&column_name'));
-----------------------------------------
 
That did the trick.

Thanks :^) Clayton T. Paige
claytonpaige@yahoo.ca

Programmer Extraordinaire

========================================================

"Who is General Failure? and Why is he reading my disk drive?"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top