Looking for some advice related to optimal design in the following scenario.
- There is a Cases table (represents cases of inventory)
- There is a LocationInventory table (represents locations with inventory)
- Then I have an InventoryNeed table or tables (this is the crux of the question), that needs to account for cases and locations.
Option A:
One table with 2 foreign key columns in which one and only one of the foreign keys would be populated.
Table: Inventory Need
- CaseId (FK)
- LocationInventoryId (FK)
- NeededQuantity
In this case either CaseId or LocationInventoryId would null and the other populated.
Option B:
Two tables for each need type that will frequently be UNION'ed to get summary data.
Table: InventoryNeedsCases
- CaseId (FK)
- NeededQuantity
Table: InventoryNeedsLocations
- LocationInventoryId (FK)
- NeededQuantity
Option C:
One table with no referential integrity.
Table: InventoryNeedsCases
- NeedType (values of Case or Location)
- NeedId (represents the primary key of either Case or LocationInventory based on NeedType).
- NeededQuantity
And the winner is? I'd probably narrow it down to say A or B to ensure data integrity...but not sure which is best from there. Or maybe there is an option D (like creating a base table with common columns...)
UPDATED SCENARIO
When I posted this last night, I was only thinking downstream, but there are also upstream dependencies to these same tables. I made some drawings that may hopefully explain it better. With this advent, option B starts to explode the nbr of tables involved, and after reading this SE answer...I am now leaning more towards A.
Pics below. Then red represent Inventory Needs, Green represents Inventory sources to meet those needs. And yellow is the question at hand...how to link the reds and greens efficiently.