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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
rrjegan17
Having to match all 112 columns to each other will take forever. Is there a simpler way?
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.
ASKER
aarontomosky
when I try to INSERT I get error
Viloation of PRIMARY KEY constraint. Cannot insert duplicate key....
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
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..
Yes, Generate a INSERT script from SSMS which would have mapped all the 112 columns for you..
Select * From livedb_restore.SCHEMANAME.
where RecID = "820d0d09"