0

I have a table A with a composite primary key and I have table B where I need to have Table A's colum(s) as foreign key. Do I need to add both column's of Table A in Table B as foreign key?

Please suggest.

David
  • 34,223
  • 3
  • 62
  • 80
DotnetSparrow
  • 27,428
  • 62
  • 183
  • 316

3 Answers3

3

Yes you have to add all the columns from table A that defines the primary key to table B.

Mikael Eriksson
  • 136,425
  • 22
  • 210
  • 281
  • +1. If you didn't add all of the columns then you couldn't uniquely identify the rows from table A. – David Apr 13 '11 at 05:58
1

Create a surrogate in table A to use as the primary key, and use the composite key columns as a superkey (create a unique, non-null index on the columns). Have the foreign key in table B refer to the surrogate column.

Community
  • 1
  • 1
outis
  • 75,655
  • 22
  • 151
  • 221
0

Yes you can add both column of table A in table B and can make only One column of table A as foreign Key in table B and also can make both column of table A as foeign key in table B.