Query on foreign key?



IBM's flagship relational database management system

Query on foreign key?

Postby diptisaini » Wed Aug 03, 2011 2:45 pm

Can i define a foreign key on the table without specifying the primary key? and i have created the unique index on the table as well. Please expalin me with some example.
diptisaini
 
Posts: 90
Joined: Sun Mar 14, 2010 5:12 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Query on foreign key?

 

Re: Query on foreign key?

Postby GuyC » Wed Aug 03, 2011 6:27 pm

for a foreign key , you need two tables: a parent and a child .
So please tell us
on which you don't have a primary key
on which you have a unique index
GuyC
 
Posts: 315
Joined: Tue Aug 11, 2009 3:23 pm
Has thanked: 1 time
Been thanked: 4 times

Re: Query on foreign key?

Postby diptisaini » Thu Aug 04, 2011 4:25 pm

On a parent table i have not defined primary key .But, i am having the unique index on it then shall i create a foreign key on child table?
diptisaini
 
Posts: 90
Joined: Sun Mar 14, 2010 5:12 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Query on foreign key?

Postby GuyC » Thu Aug 04, 2011 4:44 pm

it's all in the manual :
A foreign key can refer to either a unique or a primary key of the parent table. If the foreign key refers to a non-primary unique key, you must specify the column names of the key explicitly. If the column names of the key are not specified explicitly, the default is to refer to the column names of the primary key of the parent table.

http://publib.boulder.ibm.com/infocente ... forkey.htm
I can explain it to you, but i can not understand it for you.
GuyC
 
Posts: 315
Joined: Tue Aug 11, 2009 3:23 pm
Has thanked: 1 time
Been thanked: 4 times


Return to DB2

 


  • Related topics
    Replies
    Views
    Last post