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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:23:03+00:00 2026-05-13T15:23:03+00:00

I’m looking for a way to non-destructively alter data. I have one table that

  • 0

I’m looking for a way to non-destructively alter data. I have one table that has data that shouldn’t be edited – it is the master data. I would like to have user edits on this data, but in order to maintain the integrity of the master data I’ve created a second table that is a mirror of the structure of the master table.

My thinking is that I basically would make a view (vAdjustedData) such that this data is UNIONed together giving me a source that was the most up-to-date version of the data. (The purpose of this is to allow users to undo their data in the adjusted table and have the master tables data reverted to be current).

Columns in the tables will be nullable. The idea is that when a user wishes to make an edit that at that time the master record will be copied, changes applied, and then saved to the adjustments table. My idea for a UNION would mask the original master record with the adjusted record such that when placed in a view I will get the “current” data. When this adjustment is deleted the view will “automatically” roll back.

So I have Table_Master and Table_Adjusted. Table_Master has a primary key. Table_Adjusted also has a primary key, but it is a foreign key to the primary key of Table_Master. If both tables had a varchar column I would expect to write a view that was something similar to this:

(SELECT ID, Value
FROM Table_Adjusted)
UNION
(SELECT ID, Value
FROM Table_Master
WHERE ID NOT IN (SELECT ID FROM Table_Adjusted))

The UNION above should bring all the adjusted values and then all of the values from the master that did not have an adjustment record.

Is this the correct way to do this? To me it seems inefficient. I thought an EXCEPT would work (using SQL2K8) but it didn’t seem appropriate.

  • 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-13T15:23:03+00:00Added an answer on May 13, 2026 at 3:23 pm

    I’m assuming that you want the adjusted table to only adjust values and not add or remove values. Your query has a disadvantage that it is in theory possible to add new values which don’t even exist in the original table. This version prevents this possible risk:

    SELECT Table_Master.ID,
        CASE WHEN Table_Adjusted.ID IS NULL THEN Table_Master.Value
             ELSE Table_Adjusted.Value
        END AS Value
    FROM Table_Master
    LEFT JOIN Table_Adjusted
    ON Table_Master.ID = Table_Adjusted.ID
    

    Also your query uses a UNION DISTINCT but really you only need a UNION ALL. This slightly modified version of your query should run slightly faster:

    SELECT ID, Value
    FROM Table_Adjusted
    UNION ALL
    SELECT ID, Value
    FROM Table_Master
    WHERE ID NOT IN (SELECT ID FROM Table_Adjusted)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a jquery bug and I've been looking for hours now, I can't
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have some data like this: 1 2 3 4 5 9 2 6
I'm looking for suggestions for debugging... If you view this site in Firefox or
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a bunch of posts stored in text files formatted in yaml/textile (from

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.