Solved

PLSQL: foreign key in other tables?

Posted on 2014-11-03
3
273 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
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 76

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 10

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

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
history tablespace temp usage 2 42
Get the parent node - XMLTYPE 9 73
Oracle - SQL Query with Function 3 36
Field name with special character (Ñ) in Oracle 11 51
Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
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 shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

778 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