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 |
加上聚集索引后,此表自动排序了。