Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8149569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:52:45+00:00 2026-06-06T14:52:45+00:00

I have a question regarding my database design and its implementation that i am

  • 0

I have a question regarding my database design and its implementation that i am hoping someone can help me with?

I have a product -> retailer scenario where by the following rules apply:

product – many retailers
product – 1 brand

retailer – many products

Price can change per retailers

so i have 4 tables

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,

This works fine as you can associate products with reatilers and not all retailers offer all products etc. each product has a set brand.

My issues comes based on the brand:

a retailer can offer 1 or more brands but not necessarily all brands? i am getting an issue implementing this?

So i have created a Retailer_Brand table

retailer_brand - (retailer_Id, Brand_ID)

Even if you have specified the retailer to brand link i can still enter a product into the retailer product table that is of a brand not associated with the retailer. Am i missing something like a check constraint or is my schema wrong?

Thanks

Rob

*EDIT further details *

I am still not sure if it gives me what I require.

Perhaps If I add the following example it will clarify.

I have a list of products setup that we can offer

e.g.
Name Desc Brand
TV 32 Inch Sony
TV 64 Inch Sony
TV 20 Inch Sony
TV 64 Inch Samsung
TV 32 Inch Samsung
TV 32 Inch Panasonic

Retailers
Uberhardware – Can sell all brands of tv
SonyRetailer – Is only allowed to sell Sony products (all products)
PanasonicRetailer – Panasonic Products only

Then along comes a new retailer who I need to setup:
Phoenix Retail – Is not allowed to sell Sony products

I wish to be able to easily restrict/enable the different brands per retailer?

EDIT 2

I have implemented the Alternate key design suggested but i am still able to enter incorrect date see my data setup below and the expected results however all enrtsy into the retailer product table succeed when i would expect some to fail?

Product
ProductID BrandID
1 1
2 2

Brand
BrandID
1
2

Reatiler
1
2

RetailerBrand
RetailerID BrandID
1 1
2 1
2 2
3 1

RetailerProduct
RetaileID Brand ProductID Expected
1 1 1 OK
1 2 2 FAIL
2 1 1 OK
2 2 2 OK
3 2 2 FAIL

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T14:52:46+00:00Added an answer on June 6, 2026 at 2:52 pm
    • Alternate key (AK) — unique constraint (with index) on Product allows (ProductID, BrandID) to be referenced from RetailerProduct as a FK.

    enter image description here

    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);
    

    EDIT

    Insert some data

    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);
    

    Test

    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
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a quick question regarding a database that I am designing and making
I have a question regarding DataBase design. I have a Entity Table named: CARS
I have a very basic question regarding the design of a database. I thought
I have a question regarding this database design. I am a bit unsure of
i have a question regarding the efficiency of word press database structure. My intended
I have question regarding the SQLAlchemy. How can I add into my mapped class
I have a question regarding static function in php. let's assume that I have
I have a question regarding implementation of smart-search features. For example, consider something like
I have a question regarding editing/saving data in database using Django. I have template
I have a question regarding encodings. In my MySQL database I have encoded users

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.