I'm trying to figure out how to define foreign keys in my database.
Let's say I have three tables:
- Site (this is the site where a company resides),
- Warehouse (on this site there can be multiple Warehouses), and
- WarehouseLocation (in that warehouse there are multiple locations, eg shelves)
Now,
Site-Warehouse
is a one-to-many relationshipWarehouse-WarehouseLocation
is a one-to-many relationship
When would I describe WarehouseLocation
with multiple foreign keys, one to Warehouse.id
and one to Site.id
?
Site --[ Warehouse
| ---
| |
+----[ WarehouseLocation
When would I just use:
Site --[ Warehouse --[ WarehouseLocation
In the first option when I lookup a WarehouseLocation
I would need the Site.id
and the Warehouse.id
.
In the second option when I lookup a WarehouseLocation
I would need the Warehouse.id
, but to lookup the Warehouse I would need the Site.id
I'm confused about which option is suitable in what situation. Can someone give me some hints of the pros and cons of both options?