Home Forums SQL Server 2008 T-SQL (SS2K8) Whether order of rows will be changed when its selected? RE: Whether order of rows will be changed when its selected?

  • Just to add to what Koen said...

    The only way to guarantee that rows are returned in a specific order is when ORDER BY is used.

    It's also worth noting that ORDER BY is used more often than it is needed. Sorting is an expensive operation for SQL server, especially when dealing with millions of rows. I let the application that uses the data do the sorting whenever possible.

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001