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

  • Home
  • SEARCH
  • 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 7248231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:06:37+00:00 2026-05-28T22:06:37+00:00

OK, I am using SQL Server 2008 R2 and have a couple of relations

  • 0

OK, I am using SQL Server 2008 R2 and have a couple of relations I need to shuffle around a bit. Here is my example database design (not actual, but shows the problem).

Table - Products
Columns: ProductID - primary key
         ProductInfo - irrelevant to problem
         ModelID - foreign key to Models table
         MfgrID - foreign key to Mfgrs table

Table - Models
Columns: ModelID - primary key
         ModelInfo - irrelevant to problem

Table - Mfgrs
Columns: MfgrID - primary Key
         MfgrInfo - irrelevant to problem

In this scenario, a Product is one of a Model and is made by a Mfgr. What I need to do is associate the Mfgrs table with the Models table, as a given Model is made by a Mfgr and having separate links to the final Product is, well, bad design?

This models an actual database with live data, so it’s not just an exercise. What I want to do is add a column to Models, call it MfgrID and create a relationship from Models to Mfgrs. Then Mfgr will have a one-to-many relationship to Models and Models will have a one-to-many relationship to Products, and the world will be a better place!

Well, my world will be a better place anyway.

I’d like to create the new relationship based on the old, so that each Model gets a MfgrID
that points to the Mfgr for any given Product of that Model. Once that is established I will go back and delete the Products to Mfgrs relationship.

Any questions? I appreciate any and all ideas, I keep getting myself confused trying to design a succinct query to do this…

Dave

  • 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-28T22:06:38+00:00Added an answer on May 28, 2026 at 10:06 pm

    If you only have one product per model, this should do it;

    ALTER TABLE Models ADD MfgrID INT NULL FOREIGN KEY REFERENCES Mfgrs(MfgrID);
    
    UPDATE m SET MfgrID = p.MfgrID 
      FROM Models m JOIN Products p ON m.ModelID=p.ModelID;
    

    and possibly at the end if you want MfgrID to be mandatory and you have no nulls in that column;

    ALTER TABLE Models ALTER COLUMN MfgrID INT NOT NULL;
    

    And just to make sure, you should never run anyone’s random scripts from the Internet on your production database without testing first 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a database that I have created using SQL Server Developer 2008. I
I'm using SQL Server 2008. I have a database table that looks like this
I am using SQL Server 2008 and I have a database file (mydata.mdf) in
I'm using SQL Server 2008 and I have a table with three columns: Length
I'm using SQL Server 2008 Management studio viewing a 2005 server and have just
I am using SQL Server 2008 Enterprise. I have created a very simple test
Background: I'm using SQL Server Management Studio 2008 and I have a query window
I have an asp.net web application written in C# using a SQL Server 2008
Ok, I'm using SQL Server Express 2008 and .Net 3.5 (c#) I have a
I'm using SQL Server 2008. My database is almost 2GB in size. 90% of

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.