Slee
Slee

Reputation: 28248

UPDATE record in one database with values from another in SQL Server 2008?

I need to update my new database with data from 1 column in my old database. Basically based on matching ItemID's I need to set the Description column in my new DB with the values in the old DB. I can see what needs to be updated when I do a join but I am not sure how to handle this update properly.

Upvotes: 20

Views: 36231

Answers (1)

Martin Smith
Martin Smith

Reputation: 452977

BEGIN TRANSACTION

UPDATE t1
SET    Description = t2.Description
FROM   db1.dbo.foo t1
       JOIN db2.dbo.foo t2
         ON t1.ItemID = t2.ItemID

SELECT * FROM db1.dbo.foo
--prevents changes from being committed
ROLLBACK

Upvotes: 35

Related Questions