SQL跨表更新

[一篮饭特稀原创,转载请注明出自http://www.cnblogs.com/wanghafan/p/4384039.html

前提:两张表要更新的字段、关联字段结构一致

更新库:FJPDI_TZGL

提取库:FJPDI_TZGL_29

表:DataChangesTempT

更新字段:REASON

关联字段:IID

目标:把FJPDI_TZGL_29中DataChangesTempT的REASON字段更新到FJPDI_TZGL_中DataChangesTempT的REASON字段

查询语句:

SELECT IID,REASON FROM FJPDI_TZGL.dbo.DataChangesTempT
SELECT IID,REASON FROM FJPDI_TZGL_29.dbo.DataChangesTempT

更新语句:

UPDATE FJPDI_TZGL.dbo.DataChangesTempT 
SET REASON= d.REASON
FROM  FJPDI_TZGL_29.dbo.DataChangesTempT d 
WHERE FJPDI_TZGL.dbo.DataChangesTempT.IID=d.IID 

posted @ 2015-04-01 15:38  一篮饭特稀  阅读(1245)  评论(0编辑  收藏  举报