Skip to content

Instantly share code, notes, and snippets.

@ghotz
Created August 17, 2022 08:27
Show Gist options
  • Save ghotz/9bee625c09acca5082efbae31d2647b2 to your computer and use it in GitHub Desktop.
Save ghotz/9bee625c09acca5082efbae31d2647b2 to your computer and use it in GitHub Desktop.
Get tempdb usage stats for all databases
DROP TABLE IF EXISTS #tmp
CREATE TABLE #tmp
(
[database_name] [NVARCHAR](128) NULL,
[database_id] [INT] NULL,
[file_id] [SMALLINT] NULL,
[filegroup_id] [SMALLINT] NULL,
[total_page_count] [BIGINT] NULL,
[allocated_extent_page_count] [BIGINT] NULL,
[unallocated_extent_page_count] [BIGINT] NULL,
[version_store_reserved_page_count] [BIGINT] NULL,
[user_object_reserved_page_count] [BIGINT] NULL,
[internal_object_reserved_page_count] [BIGINT] NULL,
[mixed_extent_page_count] [BIGINT] NULL,
[modified_extent_page_count] [BIGINT] NULL
)
EXEC sp_msforeachdb N'USE [?]; INSERT INTO #tmp SELECT DB_NAME() as database_name, * FROM sys.dm_db_file_space_usage'
SELECT * FROM #tmp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment