sql2014 order by

Sqlserver2008升級到sqlserver2014的過程中,採用orderby 的語句可能出現個問題,下面舉個例子:

select 1 分組 into tempdb..baizhu003

insert into  tempdb..baizhu003

select 2

insert into  tempdb..baizhu003

select 3

insert into  tempdb..baizhu003

select 1

insert into  tempdb..baizhu003

select 2

insert into  tempdb..baizhu003

select 3

 

select * into tempdb..baizhu004 from tempdb..baizhu003 order by 分組

select * from tempdb..baizhu004

sqlserver2008運行結果:

分組

1

1

2

2

3

3

Sqlserver2014運行結果:

分組

1

2

3

1

2

3

 

解決辦法是給表加上聚集索引:

create clustered index idx on tempdb..baizhu004(分組)

select * from tempdb..baizhu004

結果如下

分組

1

1

2

2

3

3

 

加上聚集索引後,此表自動排序了。

發佈了48 篇原創文章 · 獲贊 12 · 訪問量 15萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章