Database Structure Advice Needed

前端 未结 8 704
别跟我提以往
别跟我提以往 2021-01-29 23:15

Im currently working on a site which will contain a products catalog. I am a little new to database design so I\'m looking for advice on how best to do this. I am familiar wit

8条回答
  •  再見小時候
    2021-01-29 23:37

    Now, this all seemed fine and dandy, until I realized that the category "wood" would also be used under propeller -> airboat -> (wood). This would mean, that "wood" would have to be recreated every time I want to use it under a different parent. This isn't the end of the world, but I wanted to know if there is a more optimal way to go about this.

    What if you have an aircraft that is wood construction, but the propeller could be carbon fiber, fiberglas, metal, graphite?

    I'd define a table of materials, and use a foreign key reference in the items table. If you want to support more than one material (IE: say there's metal re-inforcement, or screws...), then you'd need a corrollary/lookup/xref table.

    MATERIALS_TYPE_CODE table

    • MATERIALS_TYPE_CODE pk
    • MATERIALS_TYPE_CODE_DESC

    PRODUCTS table

    • PRODUCT_ID, pk
    • MATERIALS_TYPE_CODE fk IF only one material is ever associated

    PRODUCT_MATERIALS_XREF table

    • PRODUCT_ID, pk
    • MATERIALS_TYPE_CODE pk

    I would also relate products to one another using a corrollary/lookup/xref table. A product could be related to more than one kitted product:

    KITTED_PRODUCTS table

    • PARENT_PRODUCT_ID, fk
    • CHILD_PRODUCT_ID, fk

    ...and it supports a hierarchical relationship because the child could be the parent of soemthing else.

提交回复
热议问题