Page 1 of 1

Query on foreign key?

PostPosted: Wed Aug 03, 2011 2:45 pm
by diptisaini
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.

Re: Query on foreign key?

PostPosted: Wed Aug 03, 2011 6:27 pm
by GuyC
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

Re: Query on foreign key?

PostPosted: Thu Aug 04, 2011 4:25 pm
by diptisaini
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?

Re: Query on foreign key?

PostPosted: Thu Aug 04, 2011 4:44 pm
by GuyC
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