Monday, June 15, 2020

T-SQL script to know "What is Stored in TempDB"


List of currently stored in their TempDb. If you run the following query you would get the detailed list.

SELECT tb.name AS [Temporary Object Name],
ps.row_count AS [# rows],
ps.used_page_count * 8 AS [Used space (KB)],
ps.reserved_page_count * 8 AS [Reserved space (KB)]
FROM tempdb.sys.partitions AS prt
INNER JOIN tempdb.sys.dm_db_partition_stats AS ps
ON prt.partition_id = ps.partition_id
AND prt.partition_number = ps.partition_number
INNER JOIN tempdb.sys.tables AS tb
ON ps.object_id = tb.object_id
ORDER BY tb.name

No comments: