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-11-11, 00:56
pratikp.vasani pratikp.vasani is offline
Registered User
 
Join Date: Jul 2011
Posts: 16
Primary and foreign keys.

Hello,
I have two tables the Main table and the Child table.
The Main table has primary keys and thye child table has the foreign keys refering to the primary keys of the Main table.
Can I make the foreign keys as the primary keys also in the Child table?
Or only the foreign keys ias enough.
Reply With Quote
  #2 (permalink)  
Old 07-11-11, 01:10
singhipst singhipst is offline
Registered User
 
Join Date: Jul 2006
Location: Bangalore
Posts: 57
if you make foreign key in your child table as primary key then you will loose integrity of your data because you can insert different data in your primary table as well as child table.
But if you define foreign key in your child table that mean you are ensuring that no other data except the primary key (in your main table) has can be inserted into foreign key (in your child table).

Now decision is your, what way you want to implement.
__________________
Ritesh Kumar Singh
IBM Certified DB2 DBA for LUW
**Knowledge Is Theft If Not Shared !!**

Last edited by singhipst; 07-11-11 at 06:32.
Reply With Quote
  #3 (permalink)  
Old 07-11-11, 01:18
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Quote:
Originally Posted by pratikp.vasani View Post
Hello,
I have two tables the Main table and the Child table.
The Main table has primary keys and thye child table has the foreign keys refering to the primary keys of the Main table.
Can I make the foreign keys as the primary keys also in the Child table?
Or only the foreign keys ias enough.
Yes, you can do that, but the question is why do you have two different tables with the same PK? If you are doing that for some extreme performance requirement then it might be OK, but it is not 3rd normal form.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
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