两个数据库之间的数据复制
有两个数据库D1和D2,D1有表T1,T1中有字段ID1和Money1,D2有表T2,T2中有字段ID2和Money2,怎么样把D2的T2表ID2对应D1的T1里的ID1的数据覆盖?SQL应该怎么写
[最优解释]
use d2
update a set money2=b.money1 from t2 a inner join d1.dbo.t1 b on a.id2=b.id1
[其他解释]
use D2
go
update T2
SET Money2=D1..Money1 FROM D1..T1 WHERE T2.ID2=D1..T1.ID1
UPDATE T2
SET T2.MONEY2 = T1.MONEY1
FROM D2.T2
INNER JOIN D1.T1 ON T2.ID2 = T1.ID1