If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Primary And Foreign keys.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-20-11, 09:47
pratikp.vasani pratikp.vasani is offline
Registered User
 
Join Date: Jul 2011
Posts: 16
Primary And Foreign keys.

Hi,
I have a Main table with 7 Primary keys.
I also have a Child table which I want to relate it to Main table via Foreign keys.
Can I use the 6 Foreign keys in Child Table as reference to only the 6 primary keys instead of 7 to the Main Table.
When I am doing this I am getting Errors as:-

SQL State = 42890 SQL Code = -573 SQL Message = A column list specified in the references clause of constraint "FL_DESIG..." does not identify a unique constraint of the parent table or nickname "MBID.TMST". Exception message = com.ibm.db2.jcc.c.SqlException: A column list specified in the references clause of constraint "FLI_DESIG..." does not identify a unique constraint of the parent table or nickname "MBID.TMST".
Reply With Quote
  #2 (permalink)  
Old 07-20-11, 09:59
przytula_guy przytula_guy is offline
Registered User
 
Join Date: Apr 2006
Location: Belgium
Posts: 1,159
one table can only keep 1 primary key
different foreign keys can point to the same pk
see
Designing primary key constraints
__________________
Best Regards, Guy Przytula
Database Software Consultant
DB2 UDB LUW Certified V7-V8-V9-V9.7 DB Admin - Dprop..
Information Server Datastage Certified
http://www.infocura.be
Reply With Quote
  #3 (permalink)  
Old 07-20-11, 10:11
pratikp.vasani pratikp.vasani is offline
Registered User
 
Join Date: Jul 2011
Posts: 16
But I wanted those senev columns to uniquely define my rows.
And in the Child key a foreign key of six.
Reply With Quote
  #4 (permalink)  
Old 07-20-11, 10:45
Stealth_DBA Stealth_DBA is offline
Registered User
 
Join Date: May 2009
Posts: 472
pratikp.vasani, I think what you mean is you have 1 Primary key consisting of 7 columns. You have another table where you want to create a RI rule based on 6 columns from the Child table to only 6 of the 7 columns in the Primary Key on the Parent table.

The answer is No, you can't do that. If you have 7 columns in the Primary Key, the the Foreign Key also has to have 7 columns.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On