select id = 1
into #a
union all
select 3
union all
select 2
union all
select 5
union all
select 4select * from #adrop table #a该查询的结果一定是
1
3
2
5
4
吗? 如果数据量较大的情况下呢(超过一页)?也就是说,从没有任何约束的临时表中取数据的顺序是否一定和向临时表中存入数据的顺序一致呢?望高手指点,非常感谢!

解决方案 »

  1.   

    我碰到过用表变量做临时表的话会乱掉,用create table 再drop的就不会。希望大牛们解释一下,我当时的数据量挺大的。
      

  2.   

    谢谢olddown分享经验。怎么没有高手可以分析下?
      

  3.   

    declare @t table(id int)
    insert @t
    select id = 1  
    union all 
    select 3 
    union all 
    select 2 
    union all 
    select 5 
    union all 
    select 4 select * from @t 
    /*
    id
    -----------
    1
    3
    2
    5
    4(5 行受影响)
    */我测试表变量也一样,没有任何约束的条件下应该是按插入的顺序.
      

  4.   

    不特别指明order by 时,默认是按数据插入顺序显示的。
      

  5.   

    大虾们,冒个泡啊。给咱分析分析SQL SERVER的物理存储是怎么实现的?
      

  6.   

    LZ的例子一定是的
    因为这是MSSQL的默认排序规则, 这个默认排序规则是在不带order by  的select中有效
    具体存储的顺序, 对于into语句 来说, 就是LZ的select出来的数据是什么顺序存储就是什么顺序