电子商务数据库 ERD 帮助

发布于 2024-10-21 07:28:01 字数 665 浏览 1 评论 0原文

这实在是太伤脑筋了,我真的需要帮助! 这就是我想要实现的目标。

我有一个表名称产品。 产品可能有也可能没有最多两个可选字段。示例颜色和尺寸。

如果产品没有可选字段,则只有一行价格和数量,否则每一行可选字段都有一个价格和数量。

我知道这听起来令人困惑,请原谅我。我也很困惑。 ): 但我可以在下面给你们举几个例子。

因此,价值一百万美元的问题是,我应该创建哪些表及其字段?


[ 没有可选字段的产品 ]

价格 |数量

1.00 美元 | 2


[ 具有一个可选字段的产品 ]

价格 |数量 |尺寸

1.00 美元 | 2 |大号

2.00 美元 | 1 |小


【产品有两个可选字段】

价格|数量 |尺寸|颜色

$1.00 | 2 |大|绿色

$2.00 | 1 |小| Blue


我提出了一个想法,让两个名为 Product 和Optional 的实体与Optional 实体建立多对多关系来存储字段名称(例如 Size),而连接实体名称 Product_Optional 将存储值(例如 Large)。

但是,我仍然遇到如何将一种产品的两个可选字段绑定到相同价格和数量的问题!抱歉让您感到困惑:(

This is frying my brain, I really need help!
Here is the thing i want to achieve.

I have a Table name Product.
The product may or may not have up to two Optional field. Example Color and Size.

If the product does not have the optional field, it will have only one row of Price and Quantity, else for each row of optional field, there will be one price and Quantity.

I know this sound Confusing, pardon me. I'm confused too. ):
But i can give you guys fews example below.

So the one million dollar question is, what are the tables and it's field i should create?


[ Product Without Optional Field ]

Price | Quantity

$1.00 | 2


[ Product With One Optional Field ]

Price | Quantity | Size

$1.00 | 2 | Large

$2.00 | 1 | Small


[ Product With Two Optional Field ]

Price | Quantity | Size | Color

$1.00 | 2 | Large | Green

$2.00 | 1 | Small | Blue


I come up with an idea of having Two entity named Product and Optional to have many to many relationship with the Optional Entity to store the field name, example Size and the junction-entity name Product_Optional will store the value, example Large.

However I'm still stuck with the issue of how to bind the Two Optional Field of one product to the same price and quantity! SORRY to be confusing :(

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

淡淡の花香 2024-10-28 07:28:01

编辑:

由于您的选项未知,您可以执行以下操作

Products

id
product_name
product_description
...

ProductOptions

id
option (size, color, whatever)
value (large, blue, anything)

ProductInventory

id
product_id
product_option_id
quantity
price

那么您在 ProductInventory 中的记录将如下所示:

1 | 1 | 1 | 5 | 2.00
1 | 1 | 2 | 3 | 3.00

等等

更详细的示例,使用上面的表结构:

Products

1 | Product 1 | Prod 1 Description
2 | Product 2 | Prod 2 Description
3 | Product 3 | Prod 3 Description

ProductOptions

1 | Size | Small
2 | Size | Medium
3 | Size | Large
4 | Color | Blue
5 | Color | Red
6 | Color | Green
7 | Width | 10 Inches
8 | ... (as many as you want)

ProductInventory

1 | 1 | 1 | 5 | 2.00
(says for product 1, size small, there are 5 quantity, and cost is 2.00

2 | 1 | 2 | 17 | 3.00
(says for product 1, size medium, there are 17 quantity, and cost is 3.00

Edit:

Since your options are unknown, you could do something like this

Products

id
product_name
product_description
...

ProductOptions

id
option (size, color, whatever)
value (large, blue, anything)

ProductInventory

id
product_id
product_option_id
quantity
price

Then your records in ProductInventory would look like:

1 | 1 | 1 | 5 | 2.00
1 | 1 | 2 | 3 | 3.00

etc etc

More detailed example, using the table structure above:

Products

1 | Product 1 | Prod 1 Description
2 | Product 2 | Prod 2 Description
3 | Product 3 | Prod 3 Description

ProductOptions

1 | Size | Small
2 | Size | Medium
3 | Size | Large
4 | Color | Blue
5 | Color | Red
6 | Color | Green
7 | Width | 10 Inches
8 | ... (as many as you want)

ProductInventory

1 | 1 | 1 | 5 | 2.00
(says for product 1, size small, there are 5 quantity, and cost is 2.00

2 | 1 | 2 | 17 | 3.00
(says for product 1, size medium, there are 17 quantity, and cost is 3.00

etc

童话里做英雄 2024-10-28 07:28:01

我遇到了同样的问题,我认为你也需要不止一张桌子。试试这个:

products

id
product_name
product_price
.....

Product_options

id
product_option_name

Product_options_values

使用product_options_id 作为外键将您的product_options_values 链接到您的product_options。示例:product_option 'size' 的 Product_option_values 为 'small'、'medium'、'large'*

id
product_options_id (fk)
options_value
options_value_price

Product_options_to_products

此表将您的产品链接到您的选项。在这里,您可以为不同的产品分配不同的选项。

id
product_id
product_options_id

I have run into the same problem, and I think you need more than one table as well. try this:

products

id
product_name
product_price
.....

Product_options

id
product_option_name

product_options_values

link your product_options_values to your product_options using product_options_id as foriegn key. example: product_option 'size' has the product_option_values of 'small', 'medium', 'large'*

id
product_options_id (fk)
options_value
options_value_price

product_options_to_products

this table links your products to your options. here you'd assign different options to different products.

id
product_id
product_options_id
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文