Database Design – Referencing Multiple Foreign Keys with One Primary Key

database-design

Really hope this is the right place to ask this, but I just want to make sure this is modelled correctly.

I'm trying to create a relationship between store ownership (i.e., stores that bought other stores, or stores that are owned by other stores).

I have 3 tables:
Stores
parentStores
childStores

Essentially a store can have multiple children stores, but only one parent store. I just don't know the best way and type of relationship to link them–currently I have:

stores has a 1-to-Many relationship with parentStores (on storeID which is PK in stores and FK in parentStores)

stores has a 1-to-1 relationship with childStores (on storeID which is PK in stores and FK in childStores)

Is this the right way to go about it?

Sorry if it's an obvious question; new to 'backend' work.

Best Answer

This is a typical 1-to-n relationship: one parent store is related to several child stores.

You don't need separate junction tables to model such a relationship, and it is best to avoid unnecessary tables.

You'd add a foreign key column parent_store_id to the store table that points to the parent store. If there is no parent store, the column contains NULL.