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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:08:24+00:00 2026-05-19T03:08:24+00:00

I have a database structure that has two one-to-many relationships. I have a website,

  • 0

I have a database structure that has two one-to-many relationships. I have a website, which has many subjects, each of which has many questions. This results in three database tables, one for each of these types of data.

What I am in the process of doing is implementing a staging area – somewhere where I can make changes to these websites without affecting the live site. So, I’ve duplicated the table structure with the intent of editing the duplicates, and pushing changes to the live version when the changes are ready. I would like to do this push in one stored procedure, but I can’t figure out how to maintain the relationship between the subjects and their questions.

The website has identifying features other than its ID, so it’s easy enough to find the live version of the site, and update its information, and even to transfer that website’s subjects from the staging tables to the live tables.

Here is some pseudocode for what my plan is for the push:

-- pass in the ID of the staging website
-- get the ID of the live website
-- update live website data from staging website data
    -- this is a strict update - if there is a staging version, there will necessarily be a live version
-- delete all live subjects
-- delete all live questions
-- copy subjects from staging to live
-- copy questions from staging to live

Note that subjects and questions may be added or removed, in addition to being edited (thus, deleting and reinserting seems the best course of action).

I’ve been able to write actual code for most of this, as it’s relatively simple. But figuring out how to maintain the relationship between the subjects and the questions has been a problem. If I were doing this in a server-side scripting language, I would do something like this (again, pseudocode):

for each subject
    copy information from staging subject to live subject
    get id of new live subject
    for each question in this subject
        copy information from staging to live, setting subject ID to new live ID

As I said, I’d like to keep this all in the same stored procedure. If this is not possible, then I’ll obviously go for the above version, but for efficiency’s sake, I’d rather not have several database hits.

  • 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-19T03:08:25+00:00Added an answer on May 19, 2026 at 3:08 am

    You don’t have to create a new identity for each row. You can reuse your identities from staging.

    Assuming you have linked servers set up, you can do the following

    SET IDENTITY_INSERT MYTABLENAME ON
    
    INSERT INTO MyTableName  (IdenityColumn, Col1, Col2, Col3) 
    SELECT StagingIdentityColumn, StagingCol1, StagingCol2, StagingCol3
    FROM StagingServer.StagingDatabase.DBO.MyTableName
    
    SET IDENTITY_INSERT MyTableName OFF
    

    Of course, now you have to insert in the proper order so that you keep Referential Integrity intact.

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

Sidebar

Related Questions

I have a database structure that has a Person table which contains fields such
I have the following tables in my database that have a many-to-many relationship, which
I have a SQL Server 2008 database that has two tables. These two tables
I have a few classes, such as those that outline database table structure or
I have the option of writing two different formats for a database structure: Article
I have a table in my database which stores a tree structure. Here are
How would one structure a table for an entity that can have a one
I have a relational database with about 100 tables. Each table has unique, numerical,
I have database with many tables. In the first table, I have a field
I have a database that contains a date and we are using the MaskedEditExtender

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.