to : caixia615能稍微讲一下怎么比较执行计划吗?我不太会看。
只知道尽量避免table scan。

解决方案 »

  1.   

    这个问题需要看数据量和相关表的索引情况,特别是你select 汇总涉及的表的数据量和索引
      

  2.   

    第二种做法楼主少算了一个时间支出,就是一般临时表都没有索引,两个临时表连接如果数据量较大,那支出是巨大的还有一种情况,就是你的#table2可能汇总出的id很多在#table1是没有的,也就是多汇总了数据
    总之情况较多,不一定哪个方法效率
      

  3.   

    :(1),(2)里面select语句都是搜索两个比较大的表,但是(1)中搜索条件多,因为id可以增进进去作为搜索条件,select可能快,但是我觉得每次update都会select,(2)中搜索条件少会搜出相对多的id和movequantity,select可能慢一点,虽然增加了一个临时表,但是只需要一次,以后update #table1 的时候只需要在两个临时表中搜索了
    ----------------------------------------------------------至于(1)是搜一次还是多次,这看你的查询条件的具体写法了. 当然,还有索引.
    大多数情况下
    x=(select 聚合值 from ...  where ..)  sql查询分析器都会转换为内连接更新.至于第二种,临时表也有写表操作. 
    看你具体情况了.
      

  4.   

    update #table1 set movequantity =#table2.movequantity where #table1.id=#table2.id
    这样语句能执行?
    update #table1 set movequantity =#table2.movequantity 
    from #table1,#table2 where #table1.id=#table2.id
    改一下
    update #table1 set movequantity =(select movequantity from table2 where
    #table1.id=id
      

  5.   

    update #table1 set movequantity =(select movequantity from table2 where
    #table1.id=id)--少一个()
    update #table1
    set #table1.movequantity =#table2.movequantity  --两列都要指定表
    from #table1 inner join #table2 on where #table1.id=#table2.id