1

データベースの設計とその実装に関して質問がありますが、誰かが助けてくれることを願っていますか?

次のルールが適用される製品 -> 小売業者のシナリオがあります。

製品- 多くの小売業者 製品 - 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 不合格

4

4 に答える 4

1

私がこれを正しく理解するかどうか見てみましょう。

製品

product_id
name
description
etc

ブランド

brand_id
name
etc

小売業者

retailer_id
name
etc

リレーショナルテーブル brand_prod_ret

retailer_id
product_id
brand_id
price
etc

たとえば、Uberhardwareの小売業者は、LG、Sony、Samsungなどのテレビを販売しています。

UberhardwareRetailerテーブルに入ります

TVProductテーブルに入ります

product_idbrand_prod_retテーブルのretailer_idおよびbrand_idと一致しています。

LG 、Sony、Samsungなどのブランドに。

そしてbrand_prod_retにあなたが持っている

TVs' ID - Sony's id -Uberhardware id
TVs' ID - Samsung's id - Uberhardware id
TVs' ID - LG's id - Uberhardware id

そしてもちろん各価格。

ここに画像の説明を入力してください

これで、小売業者が現在販売しているブランドを正確に知ることができます

于 2012-06-21T15:27:08.863 に答える
1
  • 代替キー (AK) -- 一意の制約 (インデックス付き)Productにより、FK として(ProductID, BrandID)参照できます。RetailerProduct

ここに画像の説明を入力

create table Product (
  ProductID integer not null
, BrandID   integer not null
);
alter table Product add constraint pk_product primary key (ProductID);
alter table Product add constraint un_product unique (ProductID, BrandID);

create table Brand (
  BrandID integer not null
);
alter table Brand add constraint pk_brand primary key (BrandID);

create table Retailer (
  RetailerID integer not null
);
alter table Retailer add constraint pk_retailer primary key (RetailerID);

create table RetailerBrand (
  RetailerID integer not null
, BrandID    integer not null
);
alter table RetailerBrand add constraint pk_retbra primary key (RetailerID, BrandID);


create table RetailerProduct (
  RetailerID integer not null
, ProductID  integer not null
, BrandID    integer not null
);
alter table RetailerProduct add constraint pk_retprd  primary key (RetailerID, ProductID, BrandID);

alter table RetailerProduct add constraint fk1_retprd
      foreign key (ProductID, BrandID) references Product (ProductID, BrandID);

alter table RetailerProduct add constraint fk2_retprd
      foreign key (RetailerID, BrandID) references RetailerBrand (RetailerID, BrandID);

編集

データを挿入する

insert into Brand    (BrandID)                   values (1)  , (2);
insert into Product  (ProductID, BrandID)        values (1,1), (2,2);
insert into Retailer (RetailerID)                values (1)  , (2);
insert into RetailerBrand (RetailerID, BrandID)  values (1,1), (2,1), (2,2), (3,1);

テスト

insert into RetailerProduct (RetailerID, BrandID, ProductID) values (1,1,1); -- OK

insert into RetailerProduct (RetailerID, BrandID, ProductID) values (1,2,2); -- FAIL

insert into RetailerProduct (RetailerID, BrandID, ProductID) values (2,1,1); -- OK

insert into RetailerProduct (RetailerID, BrandID, ProductID) values (2,2,2); -- OK

insert into RetailerProduct (RetailerID, BrandID, ProductID) values (3,2,2); -- FAIL
于 2012-06-21T16:35:03.730 に答える
0

この容量でブランドテーブルが必要な理由はありますか?

私たちは製品と多対多の関係を築いています - ブランド小売業者 - 小売業者_製品ブランド - 小売業者ブランド

ブランド情報を Retailer_product テーブルに保持できるようです。次に、入力されたすべての新しいブランドが pk リンクされる可能性があります。または、小売業者からブランドへのルックアップ テーブルのみを入力して、新しい小売業者_製品による小売業者の関連付けの制約を適用できます。

于 2012-06-21T15:38:55.770 に答える
0

現在の構造のIMOでは、retailer_product => product => brand関係をナビゲートすることで、小売業者が完全にまたは部分的に在庫しているブランドを常に判断できるため、retailer_brandテーブルは厳密には必要ありません。

データ モデリングに影響を与える可能性のあるビジネス ドメインについて、説明をお願いできますか? (私は小売業者での経験があります)、例えば

多くの場合、ブランドは小売業者固有のものです (つまり、サプライヤーは純粋に 1 つの小売業者のためにブランド化された一連の製品を製造します)。モデルに Supplier テーブルを追加することを検討してください。

多くの場合、小売業者のチェーン内の店舗では、すべての製品を在庫しているとは限りません。モデルでこれを考慮する必要があるかもしれません。

あなたがビジネスの消費者側か供給者側かはわかりませんが、原価と販売価格の両方をモデル化する必要があるかもしれません。

価格には開始日/終了日を含める必要があります

于 2012-06-21T15:45:22.487 に答える