Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: getting foreign key dependencies
Hans Verbrugge wrote:
>
> Hi,
>
> Is there a simple way to check if a column is a reference to the
> primary key of another table?
The following will give you foreign keys that reference primary keys.
select * from user_constraints where r_constraint_name is not null;
>
> I need to get the names of the table and column where a foreign
> key points to.
This gives you table and column where foreign key is pointing to
select substr(a.CONSTRAINT_NAME,1,30) as Constraint,
decode(b.constraint_type, 'P', 'Primary', 'U', 'Unique', 'C', 'Check or Not Null', 'R', 'Foreign') as Constraint_Type, substr(b.r_constraint_name, 1, 30) as Key, substr(a.table_name, 1, 20) as Owner_Table, substr(a.column_name, 1, 30) as Owner_Column from user_cons_columns a, user_constraints b
>
> Thanks,
>
> - hans
-- Nathan ----------------------------------------------------------------- | Nathan G. Secrist | ----------------------------------------------------------------- | Evolving Systems, Inc. | Phone: (303) 802-1307 | | 9777 Mount Pyramid Court | Fax: (303) 802-1420 | | Englewood, CO 80112 | Email: nsecrist_at_evolving.com | ----------------------------------------------------------------- If it doesn't work, don't worry! If it did, you'd be out of a job!Received on Wed Jun 11 1997 - 00:00:00 CDT