开发者

database column check PK and overwrite another column

开发者 https://www.devze.com 2023-03-10 11:51 出处:网络
I have a sql server 2008 database, the code (now corrected) has accidently overwrite one column with wrong data about 50,000 rows

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

0

精彩评论

暂无评论...
验证码 换一张
取 消