title: SQL Server - last accessed timestamp on rows
body: <p>I have a table which is used as a shared cache and is periodically trimmed based on whether the individual rows have been accessed recently (i.e. if the row hasn't been accessed in a week, it is deleted). At the moment I have a <code>LastAccessed date</code> column which I update every time I access the row.</p>
  
  <p>At the moment I'm doing this by selected with an <code>UPDATE</code> query, and using the <code>OUTPUT</code> clause to actually select the data. However, this is quite slow (a typical query takes a few seconds) and I'm concerned about locking and concurrent access since many processes can access this table at once and they all need to update the last-accessed timestamp.</p>
  
  <p>Is there a better way to do this? I know about <code>ROWVERSION</code>, but this appears to be for updates, not selects. Once a row is written to the table the date, it is never changed (apart from the <code>LastAccessed</code> column, at the moment). There also doesn't appear to be any <code>SELECT</code>-based triggers which I can use.</p>