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 3954832
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:09:01+00:00 2026-05-20T02:09:01+00:00

I had posted a similar question before, but this is more specific. Please have

  • 0

I had posted a similar question before, but this is more specific. Please have a look at the following diagram:
DatabaseTableDesignIssue
The explanation of this design is as follows:

  • Bakers produce many Products
  • The same Product can be produced by more than one Baker
  • Bakers change their pricing from time-to-time for certain (of their) Products
  • Orders can be created, but not necessarily finalised

The aim here is to allow the store manager to create an Order “Basket” based on whatever goods are required, and also allow the system being created to determine the best price at that time based on what Products are contained within the Order.

I therefore envisaged the ProductOrders table to initially hold the productID and associated orderID, whilst maintaining a null (undetermined) value for bakerID and pricingDate, as that would be determined and updated by the system, which would then constitute a finalised order.

Now that you have an idea of what I am trying to do, please advise me on how to to best set these relationships up.

Thank you!

  • 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-05-20T02:09:02+00:00Added an answer on May 20, 2026 at 2:09 am

    If I understand correctly, an unfinalised order is not yet assigned a baker / pricing (meaning when an order is placed, no baker has yet been selected to bake the product).

    In which case, the order is probably placed against the Products Table and then “Finalized” against the BakersProducts table.

    A solution could be to give ProductsOrders 2 separate “ProductID’s”, one being for the original ordered ProductId (i.e. Non Nullable) – say ProductId, and the second being part of the Foreign key to the assigned BakersProducts (say ProductId2). Meaning that in ProductsOrders, the composite foreign keys BakerId, ProductId2 and PricingDate are all nullable, as they will only be set once the order is Finalized.

    In order to remove this redundancy, what you might also consider is using surrogate keys instead of the composite keys. This way BakersProducts would have a surrogate PK (e.g. BakersProductId) which would then be referenced as a nullable FK in ProductsOrders. This would also avoid the confusion with the Direct FK in ProductsOrders to Product.ProductId (which from above, was the original Product line as part of the Order).

    HTH?

    Edit:

    CREATE TABLE dbo.BakersProducts
    (
      BakerProductId int identity(1,1) not null, -- New Surrogate PK here
      BakerId int not null,
      ProductId int not null,
      PricingDate datetime not null,
      Price money not null,
      StockLevel bigint not null,
    
      CONSTRAINT PK_BakerProducts PRIMARY KEY(BakerProductId),
      CONSTRAINT FK_BakerProductsProducts FOREIGN KEY(ProductId) REFERENCES dbo.Products(ProductId),
      CONSTRAINT FK_BakerProductsBaker FOREIGN KEY(BakerId) REFERENCES dbo.Bakers(BakerId),
      CONSTRAINT U_BakerProductsPrice UNIQUE(BakerId, ProductId, PricingDate) -- Unique Constraint mimicks the original PK for uniqueness ... could also use a unique index
    )
    
    CREATE TABLE dbo.ProductOrders
    (
      OrderId INT NOT NULL,
      ProductId INT NOT NULL, -- This is the original Ordered Product set when order is created
      BakerProductId INT NULL, -- This is nullable and gets set when Order is finalised with a baker
      OrderQuantity BIGINT NOT NULL,
    
    
      CONSTRAINT FK_ProductsOrdersBakersProducts FOREIGN KEY(BakersProductId) REFERENCES dbo.BakersProducts(BakerProductId)
      .. Other Keys here
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

[I posted a similar question on serverfault.com, but had very little feedback so trying
i have already posted a similar question here, but failed to get a response
A question similar to this has been posted several time, but I cannot find
I had posted this earlier on Stack Overflow, but couldn't get a positive result.
I had posted a question in regards to this code. I found that JTextArea
I posted another one on this,, but i had to edit it really much...
I had posted a similar question earlier - a slightly different requirement here. I
This is similar to the problem posted here , but that solution doesn't work
This seems similar to a number of other questions posted, but is actually a
I have a data that looks similar to this Tables contains more than one

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.