views:

20

answers:

1

if a sql server table's column is wiped out in a database and you restore a backup to a new database, would you use merge to restore that column or run an update across the two databases?

A: 

Both would work, and maybe UPDATE is easier to write.

MERGE is aimed at more complex cases like you want to update some records, delete others, and also insert some records in the target table, absed on some condition of the source and target table.

The UPDATE would be as follows:

update db1.dbo.table1 set col =
       (select col
          from db1_bk.dbo.table1
         where db1.dbo.table1.id = db1_bk.dbo.table1.id) 

or

update db1.dbo.table1 set db1.dbo.table1.col = db1_bk.dbo.table1.col
  from db1.dbo.table1
  join db1_bk.dbo.table1 on db1.dbo.table1.id = db1_bk.dbo.table1.id 
Frank
would this work? update db1.dbo.table1 db1_bk.dbo.table1 set db1.dbo.table1.col = db1_bk.dbo.table1.col where db1.dbo.table1.id = db1_bk.dbo.table1.id ?
phill
No, it would not work. I edited my above answer to contain two variants that would work.
Frank