• kapil_kk (7/22/2013)


    John Mitchell-245523 (7/22/2013)


    kapil_kk (7/22/2013)


    Yes you are right but user PRR asked a scenario only for clustered index and if a clustered index is used then it will reorder of the data in physical order...

    You're confusing the way the data is stored with the way it's returned. As Hugo explained, they're not guaranteed to be the same.

    John

    Edit - corrected typo.

    When we declare a clustered index on a column then it will gives us the data in a sorted manner or not?

    As per the BOl and I read articles its said that after declaring a clustered index it will do reordering of data in a physical order, does this not mean that data will come in sorted manner?

    My previous reply was interrupted by a long phone conversation, so I did not see the new messages.

    The answer to your questions is: no. Without ORDER BY, there is no guarantee that the rows will be returned in clustered index order. Or in any other particular order. The only thing in SQL Server that guarantees that rows from a query are returned to the client in a particular order is an explicit ORDER BY clause, on the outermost level of the query. All other situations where you happen to see a particular order are side effects of how stuff is implemented, undocumented, unguaranteed, and prone to change.


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/