Solved

PLSQL: foreign key in other tables?

Posted on 2014-11-03
3
269 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
  • 2
3 Comments
 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
Comment Utility
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 76

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 500 total points
Comment Utility
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 10

Expert Comment

by:HuaMinChen
Comment Utility
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
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 videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
This video shows how to recover a database from a user managed backup

762 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now