gpt4 book ai didi

MySQL 关系 : Bid with products and users

转载 作者:搜寻专家 更新时间:2023-10-30 20:20:22 25 4
gpt4 key购买 nike

我有一个简单的网站,用户可以在其中对产品出价。该模型如下所示: enter image description here显然不同的用户可以出价,那么我如何绘制丢失的链接到“用户”表?

我有点困惑是使用识别关系还是非识别关系。更新:

enter image description here

最佳答案

你说:“...用户可以对产品出价。

这表明用户和产品之间存在关系(出价)。您可以将其命名为 user_bids_on_product 或仅命名为 bid

我会删除 userproduct 之间的关系(除非它意味着像产品所有者这样的其他东西)并统一你的 bidsbids_has_product 到一个表中:

user_bids_on_product
--------------------
product_id FK to product
user_id FK to user
price

(product_id, user_id) 不应 作为此表的主键,因为我们假设用户可以对产品多次出价。

您可以添加一个代理 id 并使其成为 PK,或者添加一个 bid_number 列并使复合 (product_id, user_id, bid_number) PK。您也可以使 (product_id, bid_number) 成为 PK(bid_number 可以标记每个产品的出价顺序,如本例中的拍卖)。我认为这取决于您的决定。

识别关系:

Bid table with identifying relationships


非识别关系:

Bid table with non-identifying relationships

关于MySQL 关系 : Bid with products and users,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9447557/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com