【发布时间】:2016-01-29 19:41:01
【问题描述】:
我有一个 SellerProduct 表。表格中的每一行代表卖家提供的产品信息。 SellerProduct 表具有以下列:
id (serial, pk)
productName (nvarchar(50))
productDescription (ntext)
productPrice (decimal(10,2))
sellerId (int, fk to Seller table)
不同卖家的产品可能相同,但 productName、productDescription 和 productPrice 可能因卖家而异。
例如,考虑产品 TI-89。卖家 A 可能拥有该产品的以下信息:
productName = TI-89 Graphing Calc
productDescription = A graphing calculator that...
productPrice 65.12
卖家B可能有以下产品信息:
productName = Texas Instrument's 89 Calculator
productDescription = Feature graphing capabilities...
productPrice 66.50
管理员用户需要确定不同卖家的产品是否相同。
我需要一种方法来获取这些信息(即卖家之间的产品相同)。我可以创建另一个名为 SellerProductMapper 的表,如下所示:
sellerProductId1 (int, pk, fk to SellerProdcut table)
sellerProductId2 (int, pk, fk to SellerProdcut table)
这种方法的问题在于它允许sellerProductId1 和sellerProductId2 来自给定行的同一个卖家。那不应该被允许。
如何在强制执行此约束时捕获这种多对多关系?
【问题讨论】:
-
“不同卖家的产品可能相同”。你这是什么意思?你是说你可以有相同的productName,productDescription 和不同的sellerID?或者您是说两种不同的产品可以具有相同的功能但它们是竞争对手?如果是前者,那么你有一个严重的规范化问题。如果是后者,那么我不确定您如何将某物识别为“相同”。
-
对不起...我编辑了原始帖子以包含一个示例。希望它会更好地澄清。
标签: sql many-to-many self-referencing-table