Database Design Question - Categories / Subcategories

后端 未结 6 1837
太阳男子
太阳男子 2020-12-05 12:18

I have a question for how I would design a few tables in my database. I have a table to track Categories and one for Subcategories:

TABLE Category
    Catego         


        
6条回答
  •  北荒
    北荒 (楼主)
    2020-12-05 12:28

    Having two separate tables for Categories and SubCategories depends on your situation.

    If you keep it the way it is you are limited to a Category > Subcategory scenario, as in you can't have SubCategories of SubCategories.

    If you make them into one table you need a column for ParentID. If a category is the top most it will have a ParentID of 0. If you want to allow unlimited sub categories foreach subcategory, e.g. Electronics > Recordable Media, Blueray, 4gb you will need to use recursive programming to display them.

提交回复
热议问题