Link to home
Start Free TrialLog in
Avatar of nkraemer
nkraemer

asked on

Replace Record in Table from A Backup of the Same Database

I have a Live Database called LiveDB.
I restored a copy of a backup that was taken of LiveDB two nights ago. The restored database is called LiveDB_restore

Today, by accident, I overwrote one record on a table in the LiveDB. I want to replace that record from the data in LiveDB_restore.

The table name is Loans.
The primary key field in Table Loans is called RecID.
The RecID = "820d0d09"

I would like to accomplish this via a query in SQL Server Management Studio
Please help me.
Avatar of dqmq
dqmq
Flag of United States of America image

Insert into livedb.SCHEMANAME.TABLENAME
   Select * From livedb_restore.SCHEMANAME.TABLENAME
where RecID = "820d0d09"

ASKER CERTIFIED SOLUTION
Avatar of Aaron Tomosky
Aaron Tomosky
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nkraemer
nkraemer

ASKER

rrjegan17
Having to match all 112 columns to each other will take forever. Is there a simpler way?
My way should drop right in. Back it up first of course.
aarontomosky

when I try to INSERT I get error

Viloation of PRIMARY KEY constraint. Cannot insert duplicate key....
Since you have updated the record (as opposed to deleting it), the only way it will work is you go with the update method that rrjegan17 suggested.

Since it is a PRIMARY KEY, DO NOT delete the record and try to insert it like others are recommending it.  You'll lose database integrity if you do that.

Ss
>> Having to match all 112 columns to each other will take forever. Is there a simpler way?

Yes, Generate a INSERT script from SSMS which would have mapped all the 112 columns for you..