Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sorting in SQL Server or .NET?

In terms of the memory and CPU usage, which one is better, sorting a resultset in SQL Server or in .NET?

For example, I have a stored procedure called csp_Products that returns 1000 rows - the result should be sorted by product name, is it better to sort this in SQL Server using an ORDER BY clause or is it better to do this in .NET after the data has been retrieved?

like image 308
The Light Avatar asked Dec 09 '22 06:12

The Light


2 Answers

If you can do it in SQL Server with an ORDER BY clause, then do it. SQL Server is made for retrieving and manipulating data and will be faster.

That being said, depending on the type of data being returned and the number of rows there may not be a noticeable difference. 100 rows really isn't that much data to have to worry about performance.

like image 79
Justin Niessner Avatar answered Jan 02 '23 22:01

Justin Niessner


I would go for SQL server since it can use indexes (if there are any it can take advantage of)

like image 33
Icarus Avatar answered Jan 02 '23 22:01

Icarus