?
Solved

PLSQL: foreign key in other tables?

Posted on 2014-11-03
3
Medium Priority
?
279 Views
Last Modified: 2014-11-04
as I can tell if a column is foreign key in other tables?
0
Comment
Question by:enrique_aeo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 77

Accepted Solution

by:
slightwv (䄆 Netminder) earned 2000 total points
ID: 40420839
Check the view user_cons_columns.

Here is an example:
drop table tab2 purge;
drop table tab1 purge;

create table tab1(col1 number primary key);

create table tab2(col1 number, t1_col1 number,
constraint t2_fk foreign key(t1_col1) references tab1(col1));

select * from user_cons_columns where column_name='T1_COL1';

Open in new window

0
 
LVL 77

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 2000 total points
ID: 40420844
The other view is user_constraints that will give you all the constraints on a table as well as the type.

Using the example above:
select constraint_name, constraint_type from user_constraints where table_name='TAB2';

Open in new window


Then you could also use user_cons_columns using the constraint name.  Once you get the name with the above query:
select * from user_cons_columns where constraint_name='T2_FK';

Open in new window


Or combine them with a join to get everything,
0
 
LVL 11

Expert Comment

by:HuaMinChen
ID: 40420946
Do you mean you want to adjust the column of Foreign key constraint? If yes, you must ensure the relevant values of FK columns do exist within the relevant master tables.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question