データベースの設計とその実装に関して質問がありますが、誰かが助けてくれることを願っていますか?
次のルールが適用される製品 -> 小売業者のシナリオがあります。
製品- 多くの小売業者 製品 - 1 つのブランド
小売業者- 多くの製品
小売業者ごとに価格が変更される場合があります
だから私は4つのテーブルを持っています
product - (Product_ID), product name, brand_ID(FK), details
brand - (Brand_ID), brand name
retailer - (Retailer_ID), retailer_Name, Retailer_Telephone
Retailer_Product - (Product_ID, Retailer_ID), cost,
製品を小売業者に関連付けることができ、すべての小売業者がすべての製品を提供しているわけではないなど、これはうまく機能します。各製品にはブランドが設定されています。
私の問題はブランドに基づいています:
小売業者は 1 つ以上のブランドを提供できますが、必ずしもすべてのブランドを提供できるわけではありませんか? これを実装する際に問題が発生していますか?
だから私は Retailer_Brand テーブルを作成しました
retailer_brand - (retailer_Id, Brand_ID)
小売業者からブランドへのリンクを指定した場合でも、小売業者に関連付けられていないブランドの製品を小売業者の製品テーブルに入力できます。チェック制約のようなものが欠けていますか、それともスキーマが間違っていますか?
ありがとう
ロブ
*詳細を編集 *
必要なものが得られるかどうかはまだわかりません。
おそらく、次の例を追加すると、明確になります。
私たちが提供できる製品セットアップのリストがあります
例 名前 説明 ブランド テレビ 32 インチ ソニー TV 64 インチ ソニー TV 20 インチ ソニー TV 64 インチ サムスン TV 32 インチ サムスン TV 32 インチ パナソニック
小売業者 Uberhardware - テレビのすべてのブランドを販売できます。 SonyRetailer - ソニー製品 (すべての製品) のみを販売できます。 PanasonicRetailer - パナソニック製品のみを販売できます。
次に、設定する必要がある新しい小売業者が来ます: Phoenix Retail - ソニー製品の販売は許可されていません
小売業者ごとに異なるブランドを簡単に制限/有効化できるようにしたいですか?
編集2
提案された代替キー設計を実装しましたが、まだ間違った日付を入力できます。以下のデータ設定と期待される結果を参照してください。
製品
ProductID BrandID
1 1
2 2
ブランド
BrandID
1
2
小売業者
1
2
小売
業者ブランド
小売業者 ID ブランド ID
1 1
2 1
2 2
3 1
RetailerProduct
RetaileID ブランド ProductID 予期される
1 1 1 OK 1 2 2 不合格 2 1 1 OK 2 2 2 OK 3 2 2 不合格