如何更新sql server表

时间:2015-08-21 05:16:06

标签: c# sql-server sql-update

我希望在从其他某些表复制这些值后更新sql server表中的列值。即。

我已经测试了这个查询但没有成功

update subset_aminer.dbo.sub_aminer_paper 
set sub_aminer_paper.p_abstract = 
    (select aminer_paper.p_abstract 
     from aminer.dbo.aminer_paper 
     where pid IN (86257, 116497, 119248, 135555, 147554,
                   149720, 173254, 191333, 196650, 196656,
                   .....long list of other values ......
                   1727408, 1737809, 2034956)
    )

我必须将数据从其他数据库表复制到目标数据库表。那就是使用subset_aminer.dbo.subset_aminer_paper.p_abstractaminer.dbo.aminer_paper.p_abstract

请帮助确认。感谢

2 个答案:

答案 0 :(得分:2)

update subset_aminer.dbo.sub_aminer_paper SI
set SI.p_abstract = AP.p_abstract 
     from aminer.dbo.aminer_paper AP
     where AP.pid IN (86257, 116497, 119248, 135555, 147554,
                   149720, 173254, 191333, 196650, 196656,
                   .....long list of other values ......
                   1727408, 1737809, 2034956) AND AP.ID = SI.ID

答案 1 :(得分:1)

只是一个建议,

UPDATE subset_aminer.dbo.sub_aminer_paper
SET p_abstract=aminer.dbo.aminer_paper.p_abstract 
FROM aminer.dbo.aminer_paper
WHERE subset_aminer.dbo.sub_aminer_paper.pid IN (86257, 116497, 119248, 135555, 147554,
               149720, 173254, 191333, 196650, 196656,
               .....long list of other values ......
               1727408, 1737809, 2034956)