SQL database and backup size of all databases on a server

--
SELECT @@SERVERNAME as ServerName, d.name,
ROUND(SUM(mf.size) * 8 / 1024, 0) Size_MBs
FROM sys.master_files mf
INNER JOIN sys.databases d ON d.database_id = mf.database_id
WHERE d.database_id > 4 -- Skip system databases
GROUP BY d.name
ORDER BY d.name

-- Backup size is not accurate
select database_name, max(backup_size)/1024/1024 as Backupsize_MB from msdb.dbo.backupset bs WITH (NOLOCK)
JOIN msdb.dbo.backupmediafamily bmf  WITH (NOLOCK) ON bs.media_set_id = bmf.media_set_id
WHERE bs.type = 'D'
AND bs.backup_start_date <= DateAdd(dd, -7, GETDATE())
group by database_name
--
Advertisements
This entry was posted in SQL Server, Uncategorized and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s