Skip to content

Instantly share code, notes, and snippets.

@chrismckelt
Created July 24, 2018 02:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrismckelt/9f1ed2ca338649a1efe4109d64083c07 to your computer and use it in GitHub Desktop.
Save chrismckelt/9f1ed2ca338649a1efe4109d64083c07 to your computer and use it in GitHub Desktop.
sql last backups
;with backup_cte as
(
select
database_name,
backup_type =
case type
when 'D' then 'database'
when 'L' then 'log'
when 'I' then 'differential'
else 'other'
end,
backup_finish_date,
rownum =
row_number() over
(
partition by database_name, type
order by backup_finish_date desc
)
from msdb.dbo.backupset
)
select
database_name,
backup_type,
backup_finish_date
from backup_cte
where rownum = 1
order by database_name;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment