Your suspicions are correct: your query will update every row.
You need a join:
UPDATE T1
SET NAME = T2.Name
FROM Table1 T1
JOIN OTHERDB.Table2 as T2 ON T2.Id = T1.Id
WHERE T1.Id in (
'12345678',
...
}
This assumes that Id
columns match up between databases. If that’s not the case, the join/where clauses would need adjustment.
Using an inner join means if there’s no corresponding data in the other database, there won’t be an update to null.
The where
clause now looks up on the local table’s Id
for efficiency.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…