Home Forums SQL Server 2008 SQL Server Newbies Clustered indexed primary key not in asc order when selected RE: Clustered indexed primary key not in asc order when selected

  • ugo boy (2/20/2013)


    When I ran the query, I did not specify any sort order so I am assuming the result will automatically be displayed in the sort order of the primary key init?

    Incorrect assumption.

    Without an order by, you're telling SQL you don't care about the order of the data, so you get it back in whatever order the last query operation left it. It might be the order of the index used to read the data. It might not.

    If you care about order, specify the appropriate ORDER BY. If you don't specify an ORDER BY, then you cannot assume anything about the order of the data.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass