DotnetSparrow
DotnetSparrow

Reputation: 27996

database structure

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.

Upvotes: 0

Views: 60

Answers (3)

Pratiksha Chaudhary
Pratiksha Chaudhary

Reputation: 1

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.

Upvotes: 0

outis
outis

Reputation: 77450

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.

Upvotes: 1

Mikael Eriksson
Mikael Eriksson

Reputation: 139010

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

Upvotes: 3

Related Questions