Introduction
Get all SQL Server databases sizes in Bytes, MBs & GBs. Here in script f.size is the number of 8K pages in the database, so there are f.size * 8 * 1024 bytes in the database & the rest is pure conversion to mega/giga/ etc..
There are 1048576 bytes in a megabyte, 1073741824 bytes in a gigabyte.
Script
Simply copy the below script & run it in SSMS
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
select d.name as Database_Name, f.name as Physical_File_Type, f.physical_name as Physical_File_Location, f.state_desc as Online_Status, f.size * 8.00 * 1024.00 as Size_In_Bytes, cast((f.size * 8.00 * 1024.00) / 1048576.00 as numeric (18,2)) as Size_In_MB, cast((f.size * 8.00 * 1024.00) / 1073741824.00 as numeric(18,2)) as Size_In_GB, cast(cast(v.total_bytes - v.available_bytes as float) / cast(v.total_bytes as float) * 100 as numeric(18,2)) Used_Disk_Percent from sys.master_files f inner join sys.databases d on d.database_id = f.database_id cross apply sys.dm_os_volume_stats(f.database_id, f.file_id) v order by d.name |
Result
Here is the output