Skip to content

Instantly share code, notes, and snippets.

@ronascentes
Last active May 3, 2017 19:16
Show Gist options
  • Save ronascentes/6166d90460d74ecba2a21aac45dc3c9b to your computer and use it in GitHub Desktop.
Save ronascentes/6166d90460d74ecba2a21aac45dc3c9b to your computer and use it in GitHub Desktop.
Like sp_spaceused but much better
USE <db_name>
GO
SELECT SUM((size/128.0))/1024 AS [Total Size in GB],
SUM(CAST(FILEPROPERTY(name, 'SpaceUsed') AS int)/128.0)/1024 AS [Space Used in GB],
SUM(size/128.0 - CAST(FILEPROPERTY(name, 'SpaceUsed') AS int)/128.0)/1024 AS [Available Space in GB],
sum((((size)/128.0) - CAST(FILEPROPERTY(name, 'SpaceUsed') AS int)/128.0)) / sum(((size)/128.0)) * 100 as '% Available'
FROM sys.database_files WITH (NOLOCK)
--WHERE type = 1 -- log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment