Technical Article

Database State and Backup Information

,

works only on 2005 and up.

SELECTt.name as [DB Name],
t.user_access_desc as [Access State],
t.state_desc as [Online/Offline],
((SELECT (CASE t.is_in_standby WHEN 0 THEN 'No' WHEN 1 THEN 'Yes' ELSE 'Other' END))) as [In Standby],
(COALESCE(Convert(datetime, MAX(u.backup_finish_date), 101),'Not Yet Taken')) as [Last BackUp Taken],
(((COALESCE(Convert(real(256), MAX(u.backup_size), 101),'NA'))/1024)/1024) as [Backup Size in MB],
(COALESCE(Convert(varchar(10),MAX(datediff(d, getdate(), u.backup_finish_date))),101)) as [Days since Backup],
(COALESCE(Convert(varchar(12), MAX(u.user_name), 101),'NA')) as [User Name]

 FROM SYS.DATABASES t
INNER JOIN msdb.dbo.BACKUPSET u
ON t.name = u.database_name
GROUP BY t.Name,t.is_in_standby, t.user_access_desc, t.state_desc
ORDER BY t.Name

Rate

3.6 (5)

You rated this post out of 5. Change rating

Share

Share

Rate

3.6 (5)

You rated this post out of 5. Change rating