# Thread: which can be foreign key?

1. Registered User
Join Date
Mar 2011
Posts
1

## which can be foreign key?

hi there.
before every thing i apologize because of my poor english.
there was a computer science exam that i participated in.there was many debatable problems.
one of them is a database problem:

assumeing two table,R and S with the following scheme[name:domain],what is best choise for the foregin key of r?

R(r1:d1[primary key],r2:d2,r3:d3)
S(r2:d2[P.K.],r3:d3,r4:d4)

a)r1,r2 b)r2 c)r3 d)r2,r3

the problem designer has given b as answer key,but i have selected d,because i think :
r3 is in both tables,and choosing r2 lonely can create anormally.
if there exists a record with values(v1,v2,v3)in S and there is a refrence in R to this record,it's third filed(r3) must be the same(v2) as the r2 fields(v1,r2)
i ask you to guide me!

2. SQL Consultant
Join Date
Apr 2002
Location
Posts
20,002
if R is supposed to have a foreign key to S, then we can rule out a) because r1 does not exist in S

similarly, we can rule out c) because r3 isn't unique in S

we can also rule out d) because although both r2 and r3 are in S, there is no constraint on r3 in R to be the same r3 as the r3 in S for the same r2

that leaves b) -- r2

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•