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.