DEV Community

Discussion on: eCommerce Database Design

Collapse
 
ezzdinatef profile image
Ezzdin Atef

Thank you for your suggestion! Having a single categories table with a parent set to null is indeed a valid approach in certain scenarios. This depends on the specific requirements of your application.
However, in some cases, a separate table for parent and child categories can provide additional benefits like allowing easy management of attributes of every category type and simplifies certain types of queries.

Collapse
 
jdgamble555 profile image
Jonathan Gamble

Interesting. Could you expound on this? Would like to see benefits...

Thread Thread
 
ezzdinatef profile image
Ezzdin Atef

Yes! In certain instances, I chosen to simplify the categories table by storing only the id and name of the category. Meanwhile, the sub_categories table includes additional details such as id, name, parent_id, description, icon, and a flag to signal anything new or updated in the UI. Additionally, I introduced a group_id for cases where subcategories are logically grouped under a common title.

In other scenarios, I have followed your recommended approach, especially when a client requested categories and subcategories with unlimited depth. Your approach proved to be the most suitable for handling such cases of dynamic hierarchy.