1

更新

这是我当前的数据库图,用于销售的在线鞋

  • 将有不同类别的鞋子(高跟鞋、坡跟鞋、凉鞋、高跟鞋折扣等)
  • 每双鞋会有不同的颜色,不同的尺码。对于每种颜色和尺寸,
  • 它会有不同的库存,可能有不同的订单类型(现货/预购)
  • 对于每种尺寸和颜色,可能会有不同的价格
  • 而且每双鞋的尺码和颜色都不同,它们(也许)会有不同的形象,而不是普通的

在此处输入图像描述

我做得对吗?我应该怎么做才能改进这个数据库?我真的很感谢任何反馈/意见/批评

结束更新

我是数据库设计的新手,对网上商店的数据库设计感到困惑(MySQL 数据库)

假设网上商店会出售不同颜色、尺码、不同库存和价格的鞋子,每种颜色和尺码。

我想出了这些表:

generic_shoes

id
name
category_id
details
image

颜色

id
color

尺寸

id
size
size_details

具体_鞋

id
generic_shoes_id //references to generic_shoes
name             // if the owner wants to make another name, if not then use generic_shoes' name
order_type       //ready stock or pre order

然后我想出了带有多对多rel的枢轴colors_shoes和sizes_shoes: colors_specific_shoes

id
color_id
specific_shoes_id

size_specific_shoes

id
size_id
specific_shoes_id

然后我认为不同的颜色和尺寸会有不同的库存和不同的价格,所以我想出了:

shoes_product_details

id                //will be used in the orders table
colors_shoes_id   //reference to pivot colors_shoes
sizes_shoes_id    //reference to pivot sizes_shoes
specific_shoes_id //reference to specific_shoes
stock             //each color and size will have diff stock
price             //each color and size maybe will have diff price
weight            //each size will have different weight

我认为这些桌子会很好,但后来我想,我应该用这张桌子代替吗?

删除

  1. size_specific_shoes
  2. color_specific_shoes

并且只需使用 specific_shoes_details 表中的颜色 ID 和尺寸 ID:(在下表中,我只是直接参考颜色和尺寸表)

specific_product_details 表

id                      //will be used in the orders table
color_id                //reference to colors table
size_id                 //reference to sizes table
specific_shoes_id       //reference to specific_shoes
stock                   //each color and size will have diff stock
price                   //each color and size maybe will have diff price
weight                  //each size will have different weight

我认为问题在于最后一个表是 -> 外键级联,如果删除了颜色/大小,那么它也会删除 specific_shoes_details 行。

谁能给我更好的方法?因为我不知道我应该使用哪种方法,第一个带有颜色和大小数据透视表的方法还是最后一个..

谢谢

我非常感谢任何帮助/反馈

4

2 回答 2

3

我认为您在数据库设计方面做得很好。

我会和你的最后一个一起去。您想要删除颜色或尺寸的可能性很小。你不会再做 18 号的生意了?

删除的更好选择是将颜色设置为非活动状态。添加一个活动列,以便您可以将其关闭,但仍保留库存。

我还会为特定的鞋子添加描述和/或图像。

如果您只关心这些,我相信您也可以选择不级联删除。

于 2013-08-13T05:16:11.203 回答
0

从问题的描述中,我感到有些复杂,我无法理解。我会想到你应该能够消除特定的表格。

这是我建议您考虑的架构。

  1. 颜色(color_id、color_name、active、...)
  2. 尺寸(size_id,size_name,size_description,活动,...)
  3. 类别(category_id、category_name、active、...)
  4. 图像(image_id,image_path,活动,...)
  5. order_mode (mode_id, mode_name, mode_description, ...)
  6. 鞋子(shoe_id、color_id、size_id、category_id、image_id、mode_id、库存、价格、重量……)

如果您的尺码也需要国家/地区编码,您可能会有另一个级别的详细信息。在这种情况下,考虑

  1. 尺寸(size_id、size_name、country_id、size_description、active、...)
  2. 国家 (country_id, country_name, active, ...)

请注意,我在所有表格上都留下了一个活动标志,以便您可以将其用作特定参考元素未在使用中的指示,并且您可以使用它级联到 shoes 表格。

我相信这种模式的好处是它更简单,并且尽我所能告诉它提供与您提出的相同级别的规范化。

于 2013-08-13T19:59:25.153 回答