title: Keep SQL Server table sorted inside database
body: <p>In my application I use a simple table that contains the number of times a file was accessed and the date at which it was last accessed.</p>
  
  <p>I'm trying to sort the saved entries so that the files with the highest number of accesses are always on top in the database. Also I would like to sort only the files which have been accessed in the last 7 days.</p>
  
  <p>What method should I use(with execution speed in mind)? Should I maybe write a stored procedure that takes care of the sorting and just call that every time I add or modify an entry? Should I query the entries newer than 7 days in my application, sort them, and add them at the top of the database? Any other methods are most welcome.</p>
  
  <p>Thanks, Catalin</p>