Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Sort order different from 2000

Author  Topic 

huenemeca
Starting Member

3 Posts

Posted - 2011-08-25 : 17:04:42
I am restoring a database from 2000 to 2008 R2. One of my clients is complaining that the sort order has changed. It is a select with an order on the score column. The first 2 records have the same score and it 2000 they come by one way in 2008 they come back the opposite.

I have looked and they have the same collation settings, and the 2008 is in 2000 compatibility mode. Is there anything else I can check?

Thanks,
Mike

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2011-08-25 : 17:08:13
Without a proper ORDER BY, you can never be sure of the order for the set.
If there is a column with two equal values, and you sort by that column, the first may come before the second or the opposite.
There is no guarantee without ORDER BY.

It's as simple as that.



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

huenemeca
Starting Member

3 Posts

Posted - 2011-08-25 : 17:09:26
That is what I was trying to tell my Boss, but I needed confirmation that there isn't some setting that I was missing.

Thanks
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-25 : 23:54:50
is this happening in a view. if yes, i doubt whether this is reason

http://visakhm.blogspot.com/2010/01/behaviour-of-order-by-inside-view.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2011-08-26 : 00:58:13
Parallellism? Outdated statistics?


N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

huenemeca
Starting Member

3 Posts

Posted - 2011-08-26 : 10:37:09
This is not in a view, sorry but I don't know how to check Parallellism. Updating statistics did not fix it.

Correction, Updating statistics did not fix it if you only update stats on the 2008 db. I ran it on the 2000 db and now they are in sync. Thanks for the help.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-26 : 10:53:09
EXEC sp_configure 'max degree of parallelism'
GO

this will give degree of parallelism setting of the server

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2011-08-26 : 11:11:30
Note that the sort order may change from query-to-query.

Whilst, mostly, you will probably get tie-break by the clustered index order, it is possible for part of the data you need to be in memory (from another query) and SQL may start processing that data whilst waiting for other data to be retrieved from disk. This can cause the "tie break" to be different to the clustered index. Its as rare as hen's teeth though ...

So ... if your ORDER BY is ambiguous then most of the time, indeed often "very nearly 100% of the time", the ordering will be repeatable. But it is not guaranteed.

To be guaranteed include additional tie-break columns in your ORDER BY - e.g. the PK Columns - such that each row is uniquely defined by the ORDER BY sort order.
Go to Top of Page
   

- Advertisement -