tags:

views:

34

answers:

2

I write a stored procedure for most viewed photos in my procedure, this is my procedure can u check this please is ok or is there any improvement required?

 create procedure sp_photos_selectmostviewedphotos 
 as
   select * from photos order by views desc

is it enough or required any modification

+2  A: 

First just specify the columns you really need -> replace the star in your query.

Then create an index over the views column (SortOrder DESC).

The rest should be OK :)

Greco
A: 

+1 to Greco, just to add:

I'd imagine you won't actually use ALL the records (the name indicates "most viewed photos"), so I'd stick in a TOP clause and only return however many records you actually need.

e.g.

SELECT TOP 10 Column1, Column2
FROM Photos
ORDER BY Views DESC
AdaTheDev