Database Design Question - Categories / Subcategories

后端 未结 6 1831
太阳男子
太阳男子 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:30

    Your design is appropriate. I'm a database guy turned developer, so I can understand the inclination to have Category and SubCategory in one table, but you can never go wrong by KISS.

    Unless extreme performance or infinite hierarchy is a requirement (I'm guessing not), you're good to go.

    If being able to associate multiple subcategories with a product is a requirement, to @Mikael's point, you would need a set-up like this which creates a many-to-many relationship via a join/intersect table, Product_SubCategory:

    CREATE TABLE Product (ProductID int, Description nvarchar(100))
    CREATE TABLE Product_SubCategory (ProductID int, SubCategoryID int)
    CREATE TABLE SubCategory (SubCategoryID int, CategoryID int, Description nvarchar(100))
    CREATE TABLE Category (CategoryID int, Description nvarchar(100))
    

    Hope that helps...

    Eric Tarasoff

提交回复
热议问题