title: How can I query how much time a SQL server database restore takes?
body: <p>Im trying to write a query that will tell me how much time a restore (full or log) has taken on SQL server 2008.</p>
  
  <p>I can run this query to find out how much time the backup took:</p>
  
  <pre><code>select  database_name, 
          [uncompressed_size] = backup_size/1024/1024,
          [compressed_size] = compressed_backup_size/1024/1024, 
          backup_start_date, 
          backup_finish_date, 
          datediff(s,backup_start_date,backup_finish_date) as [TimeTaken(s)], 
  from    msdb..backupset b 
  where   type = 'L' -- for log backups
  order by b.backup_start_date desc
  </code></pre>
  
  <p>This query will tell me <em>what</em> is restored but now how much time it took:</p>
  
  <pre><code>select * from msdb..restorehistory
  </code></pre>
  
  <p><code>restorehistory</code> has a column <code>backup_set_id</code> which will link to <code>msdb..backupset</code>, but that hold the start and end date for the <em>backup</em> not the restore.</p>
  
  <p>Any idea where to query the start and end time for restores?</p>