Solved

PLSQL: foreign key in other tables?

Posted on 2014-11-03
3
276 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 500 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 500 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines

729 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