Last active
August 29, 2015 14:11
-
-
Save spaghettidba/2a79d1698b1bc7847df6 to your computer and use it in GitHub Desktop.
SQL Server file used space
This file contains hidden or 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
-- This is captured from SSMS (shrink file dialog) | |
use [yourDatabase]; | |
select s.Name, CAST(CASE s.type WHEN 2 THEN s.size * CONVERT(float,8) | |
ELSE dfs.allocated_extent_page_count*convert(float,8) END AS float) AS [UsedSpaceKB] | |
,CASE s.type WHEN 2 THEN 0 | |
ELSE 5120 - dfs.allocated_extent_page_count*convert(float,8) END AS [AvailableSpaceKB] | |
from sys.filegroups AS g | |
inner join sys.database_files AS s on ((s.type = 2 or s.type = 0) and (s.drop_lsn IS NULL)) AND (s.data_space_id=g.data_space_id) | |
left outer join sys.dm_db_file_space_usage as dfs ON dfs.database_id = db_id() AND dfs.file_id = s.file_id | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment