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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:04:43+00:00 2026-05-17T15:04:43+00:00

Suppose that I have a table with the following schema: tableId field1 field2 …..

  • 0

Suppose that I have a table with the following schema:

tableId
field1
field2
…..

I have two copies of my database (backup and production). On the production instance, a query was accidentally run which did the following:

Update table set field2 = null where field1 = 'x';

I am trying to undo this query based on the data stored in the backup instance (where the bad update statement was not run).

What SQL statements would I need to run on the backup db to retrieve the tableId and values of field2? How would I convert that to appropriate update statements to fix production? There could be quite a few rows impacted by the query.

I think that I could select the erased values from the backup with the following query:

Select tableId, field2 where field1 = 'x';

However, I’m at a loss about how to convert that into an easy update statement. Any insight (or better ideas) would be appreciated.

  • 1 1 Answer
  • 3 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-17T15:04:44+00:00Added an answer on May 17, 2026 at 3:04 pm

    You’ll need the data to update in the same database, so when you do that select from your backup where field1 = ‘x’, save that to a temporary table and copy that to your production table.

    You’ll also need some sort of primary key between those two tables — if you don’t have that, how will you know which field2 needs to be updated?

    For instance, if your table had

    field1   field2
    x        5
    x        9
    x        null
    y        5
    

    and now has

    field1   field2
    x        null
    x        null
    x        null
    y        5
    

    and if there are other fields, how will you distinguish the proper record x/5 from x/9, and more importantly, from the field2 that was null before the update?

    If you do have some sort of primary key, then you can update table1 (field2) as select field2 from backuptable where table1.field1 = backuptable

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

Sidebar

Related Questions

Suppose I have a database table that has a timedate column of the last
Suppose I have an array that mimics a database table. Each array element represents
Suppose I have two columns in a table that represents a graph, the first
Suppose that we have the following partial ER diagram: Notice that the attachments table
I have a table Template with following columns: ID, [Text] Suppose I have two
Suppose I have the following schema: Table: Showing showing_id movie_id theater_id show_date show_time Table:
Suppose that I have two Hibernate POJOs: Customer and Order. The Order table has
suppose that I have this RDBM table ( Entity-attribute-value_model ): col1: entityID col2: attributeName
Lets suppose that I have a Category table with a column that holds the
Suppose I have table A with a field that can be either 1 or

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.