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.
Asked
Active
Viewed 3.5k times
1 Answers
35
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

Lynn Langit
- 4,030
- 1
- 23
- 31

Martin Smith
- 438,706
- 87
- 741
- 845
-
1@Slee - Yep. You might want to put it inside an explicit transaction and do a quick review of the results before commiting as well. – Martin Smith Apr 20 '11 at 18:56
-
hello @MartinSmith could you please add the the explicit transaction to the example above pls?? I never worked before with transaction and I would like to start for this kind of things. – Emilio Gort May 13 '15 at 13:31
-
Don't forget to add the server first (like I did) using sp_addlinkedserver – Patrick Schomburg Oct 11 '18 at 13:19