VanillaGranilla

TableSizesAcrossEntireServer.sql

Jul 29th, 2019
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 0.62 KB | None | 0 0
  1. use master;
  2. go
  3.  
  4. create table ##tablesizes
  5. (
  6.     db varchar(100),
  7.     name varchar(100),
  8.     sizeMB float
  9. );
  10.  
  11. exec sp_ineachdb @command =
  12. 'INSERT INTO ##tablesizes
  13. SELECT db=''?'', sys.objects.name, SUM(reserved_page_count) * 8.0 / 1024 as sizeMB
  14. FROM sys.dm_db_partition_stats, sys.objects
  15. WHERE sys.dm_db_partition_stats.object_id = sys.objects.object_id
  16. GROUP BY sys.objects.name
  17. ORDER BY sizeMB DESC ;
  18. ',
  19. @help=1
  20.  
  21. select top 100 * from ##tablesizes order by sizeMB desc;
  22.  
  23. select top 50 name, sum(sizeMB) as TotalSizeMB from ##tablesizes group by name order by TotalSizeMB desc;
  24.  
  25. drop table ##tablesizes;
Advertisement