Result sort order differs since DB Maint. Job

  • Hi All,

    I had users complaining about performance issues in a database, so I ran a db maintenance plan and selected the option to reorganise data and index pages.

    Now the performance is beautiful...however some stored procedures no longer return data in the sort order they were once in. For example I have a stored proc that used to return data sorted by surname, now the results are not sorted. The stored proc never had a order by clause on the select statement to start.

    Am I going to have to add the sort clause to all stored procs that no longer return results sorted? Was it just a co-incidence that these stored procs functioned correctly in the first place? Is there a way to make the data return as is was initially?

     

    Thanks in Advance,

    Terry Pino

  • Terry,

    You must always specify an ORDER BY to GUARANTEE that results will be returned in that order.

    More often that not, if your data is physically in the order that you want, it will be returned in that order.  But that's just because it's convenient for SQL Server to do so.  In a multi-CPU environment they may get mixed up, plus there's a whole bunch of situations that can aslo affect the ordering.

    In short, if you want an specific order, use ORDER BY.

     


    Cheers,
    - Mark

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply