T-SQL 101: 16 Ordering the output of a T-SQL query
When you run a query against SQL Server, you might want the rows to be returned in a specific order. However, the first thing you should ask yourself is whether that’s needed at all.
Sorting can be a very expensive operation if there is no suitable index that’s already sorted the data for you. And the question is: should SQL Server be the one doing the sorting? In many cases, the client application that’s reading the data might be a better place to do the sorting. That’s not always true but it’s worth considering. You often have way more clients than your single database server, and sorting data unnecessarily in the database server could limit your ability to scale your system to higher volumes.
2019-05-06