Search

Wednesday, July 27, 2011

Query to get the total size of all databases in one instance

This codes gives both indivual file sizes as well as the total size of all databases in one instance. Needed when calculating backup and restore times.

Example:

SELECT SUM(size*(8192/(1024.*1024))) as' Size in Mb',
SUM(size*(8192/(1024.*1024)))/1024 as' Size in gb',
SUM(size*(8192/(1024.*1024)))/1024/1024 as' Size in Tb'
FROM sys.master_files
go
SELECT name,file_id, size*(8192/(1024.*1024)) as' Size in Mb'
FROM sys.master_files

No comments:

Post a Comment