database column check PK and overwrite another column
I have a sql server 2008 database, the code (now corrected) has accidently overwrite one column with wrong data about 50,000 rows The rows might have changed since the backup, but the primary key is intact now I have two database 开发者_运维知识库one with correct data in one column and one with incorrect data.
Can anyone help with a script to recover this columns data.
You could use an update
statement to copy data from the restored database:
update wrong
set WrongColumn = [right].WrongColumn
from ProductionDb.dbo.Table1 as wrong
join RestoredDb.dbo.Table1 as [right]
on [right].PrimaryKeyCol = wrong.PrimaryKeyCol
Use tablediff that will generate a script for you:
http://msdn.microsoft.com/en-us/library/ms162843.aspx
精彩评论