简体   繁体   English

多色产品的数据库架构

[英]Database Schema for Multi-Color Products

I am designing a database and would like some feedback on what I have so far. 我正在设计一个数据库,希望获得有关到目前为止的一些反馈。

Here are the requirements: Each product has multiple colors. 要求如下:每个产品都有多种颜色。 Each product must be under a certain category. 每个产品必须属于某个类别。 Each category may have a subcategory. 每个类别可能都有一个子类别。

A example relationship would be 一个示例关系是

Eyes[Cat]
   EyeProduct[Product]
      Color1[color]
      ...
      ColorN[color]

Lips[Cat]
   Lipgloss[Subcat]
      CoolLipgloss[Product]
          Color1[color]
          ...
          ColorN[color]

Here is my database design so far: 到目前为止,这是我的数据库设计:

Categories
-id     (pk)
-subcat_id  (fk)
-name
-description
-active     (boolean)

Sub Category
-id         (pk)
-product_id     (fk)
-name
-description


Products
-id     (pk)
-name
-price
-weight
-descritpion
-ingredients
-product_img
-active     (boolean)

SKU
-sku    (pk)
-product_id     (fk)
-name
-image_small
-image_med
-image_Lrg
-active     (boolean)

Would it be a good idea to implement a image tables. 实现图像表是个好主意。 This table will hold a reference to all images used for each SKU (color) and any extra product images. 该表将包含用于每个SKU(彩色)的所有图像以及任何其他产品图像的参考。 I think it makes more sense since each sku entry can have more than one picture as well. 我认为这更有意义,因为每个SKU条目也可以具有多个图片。

Looks good. 看起来不错。 Just couple notes regarding relationships (fk), I think they should be changed: 关于关系(fk)的一些注意事项,我认为应该予以更改:

Categories
-id     (pk)
-name
-description
-active     (boolean)

Sub Category
-id         (pk)
-category_id     (fk)
-name
-description


Products
-id     (pk)
-subcategory_id     (fk)
-name
-price
-weight
-descritpion
-ingredients
-product_img
-active     (boolean)

SKU
-sku    (pk)
-product_id     (fk)
-name
-image_small
-image_med
-image_Lrg
-active     (boolean)

BTW. 顺便说一句。 You can use partial path for images, this will save you 2 text fields. 您可以为图像使用部分路径,这将为您节省2个文本字段。 For example you have 3 images for sku 1111: 例如,您有3张SKU 1111图片:

/tmp/image1111small.jpg
/tmp/image1111med.jpg
/tmp/image1111lrg.jpg

Actually only "/tmp/image1111" have to be stored, and full path would be restored by adding "small.jpg", "med.jpg" and "lrg.jpg" to the path accordingly. 实际上,仅需要存储“ / tmp / image1111”,并且可以通过在路径中添加“ small.jpg”,“ med.jpg”和“ lrg.jpg”来恢复完整路径。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM