I am creating a relationship between 2 tables:
The relationship I like to form is between the Inventory an InventoryExtended tables.
The primary key for the Inventory table is InvID (Inventory ID).
The reason why I created the InventoryExtended is becauses only 1% of the inventory items in the Inventory table will need additional or extended fields, the rest will not.
Instead of adding these additional fields in the Inventory table where 99% will be blank for 50 additional fields that I need I decided to create an InventoryExtended table and store the 50 fields there.
The relationship between the Inventory an InventoryExtended table will be 1 to 1.
Meaning, for the 1% of the records in the Inventory table , the InvId will be the same as the InvId in the InventoryExtended table.
My question is that should the InvID in the InventoryExtended table be a FK (Foreign Key) or should it be a PK and a FK?
I am thinking it should be a PK and a FK as there the InvID will be unique in the InventoryExtended table.
Thanks in advance.
You are correct.
The
InvIDshould be aPRIMARY KEYand aFOREIGN KEYas it will be unique in theInventoryExtendedtable.This type of relationship is indeed 1:1 or (more accurately)
1::0..1, as only some of the rows in theInventorytable will have a related row inInventoryExtended.Also note that the
InventoryExtended (InvID)should not have theIDENTITYproperty, even if theInventory (InvID)has it.