欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

SQLServer统计数据库各表空间大小和数据量

程序员文章站 2022-04-14 20:38:23
...

SQLServer统计数据库各表空间大小和数据量

with temp as (
select convert(char(8), getdate(), 112) as date_id,
       tablename N'table_name',
       max(used_G) as "use_space_G",
       max(rows) as row_nums,
       getdate() as insert_time
  from (select object_name(id) tablename,
               8 * reserved / 1024 reserved,
               (8 * dpages / 1024.0/1024.0) used_G,
               8 * (reserved - dpages) / 1024 unused, 
               8 * dpages / 1024 - rows / 1024 * minlen / 1024 free,
               rows
          from sysindexes a) as b
 group by tablename
 )
 select date_id,table_name,use_space_G,row_nums,insert_time
 from temp
 where use_space_G>0.01
 order by row_nums desc

SQLServer统计数据库各表空间大小和数据量