Created
October 9, 2015 13:58
-
-
Save Spaider/3b8659023fb2cc7b29cb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with db_file_cte as | |
( | |
select | |
name, | |
type_desc, | |
physical_name, | |
size_mb = | |
convert(decimal(11, 2), size * 8.0 / 1024), | |
space_used_mb = | |
convert(decimal(11, 2), fileproperty(name, 'spaceused') * 8.0 / 1024) | |
from sys.database_files | |
) | |
select | |
name, | |
type_desc, | |
physical_name, | |
size_mb, | |
space_used_mb, | |
space_used_percent = | |
case size_mb | |
when 0 then 0 | |
else convert(decimal(5, 2), space_used_mb / size_mb * 100) | |
end | |
from db_file_cte; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment