要先查询几张表得数据(表名不固定),然后更新另一张表得一些数据。数据量有点大,怎样做能提高更新时间和方法,请附代码,是新手

解决方案 »

  1.   

    1、生成临时表
    select * into #tmp -- 插入到临时表
    from a,b,c,d      -- 按需查询n个表结果2、将临时表中的多个字段更新到一张表
    update yourtable set col1 = y.b, col2=y.c
    from #tmp y where y.id = yourtable.id
      

  2.   


    测试数据都舍不得给。
    ;with t
    as(
    select ...... from tbl --你的查询语句
    )
    update 需要更新的表
    set 需要更新的字段=t.对应的字段...... from  t where t.标识字段=tbl.标识字段