Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2011

    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)

    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. #2
    Join Date
    Apr 2002
    Toronto, Canada
    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 | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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