File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Foreign key access problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Foreign key access problem" Watch "Foreign key access problem" New topic

Foreign key access problem

Naren Chivukula
Ranch Hand

Joined: Feb 03, 2004
Posts: 577


I have two tables table1 and table2. I have 3 fields in each tables. I made two of the fields in table1 as composite primary key. Now, I want to make one among these fields as foreign key to table2. When I give like this and try to run, I'm getting an error like

SQL> Error Message: The Foreign Key TABLE1_0_SYSTEMNAMEDCONSTRAINT_TABLE2_FOREIGNKEY_NAME does not map to a primary key in table TABLE2. Each foreign key must reference a table that has a primary key made up of the same columns as specified in the reference list.

Here, I want to make that field(one among the composite primary key participants) as foreign key in my table2. Is it possible? If so how?

Thanks in advance,

(OCEEJBD6, SCWCD5, SCDJWS, SCJP1.4 and Oracle SQL 1Z0-051)
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33117

It is possible to do that. Do you have a one field primary key on table 2? Is it the same datatype?

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I agree. Here's the link:
subject: Foreign key access problem
It's not a secret anymore!