zoukankan      html  css  js  c++  java
  • 05-SQLServer查看当前库下大于1G的表

    1、脚本(分区表显示为多个结果)

    ;with t1 as 
    (
    select 
    t.name as tableName,
    
    cast(round(((sum(a.total_pages) * 8) / 1024.00 /1024.00),2) as numeric(36,2)) as totalSpaceGB,
    p.rows as rowCounts
    from sys.tables t
    inner join 
    sys.indexes i on t.OBJECT_ID = i.OBJECT_ID
    inner join
    sys.partitions p on i.object_id = p.object_id and i.index_id =p.index_id
    inner join 
    sys.allocation_units a on p.partition_id = a.container_id
    where 
    t.is_ms_shipped = 0
    and i.object_id > 255 
    group by 
    t.name,p.rows
    )
    select * from t1 where totalSpaceGB >1 order by totalSpaceGB desc

    2、脚本(分区表显示为1条记录)

    ;with t1 as 
    (
    select 
    t.name as tableName,
    
    cast(round(((sum(a.total_pages) * 8) / 1024.00 /1024.00),2) as numeric(36,2)) as totalSpaceGB,
    p.rows as rowCounts 
    from sys.tables t
    inner join 
    sys.indexes i on t.OBJECT_ID = i.OBJECT_ID
    inner join
    sys.partitions p on i.object_id = p.object_id and i.index_id =p.index_id
    inner join 
    sys.allocation_units a on p.partition_id = a.container_id
    where 
    t.is_ms_shipped = 0
    and i.object_id > 255 -- and t.name='HTML_TX_2018'
    group by 
    t.name,p.rows
    )
    select * into #table_temp from t1 where totalSpaceGB >1 order by totalSpaceGB desc
    select tableName,sum(totalSpaceGB) as GB,sum(rowCounts) as cnt from #table_temp --where tableName='HTML_TX_2018'
    group by tableName
    order by sum(totalSpaceGB) desc
    drop table #table_temp
  • 相关阅读:
    解决谷歌高版本没有设置字符编码的选项的问题
    System.nanoTime与System.currentTimeMillis的区别
    jQuery学习笔记(一)
    linux问题
    阿里资源学习
    PHP-Gealman
    php-fpm
    GIT使用
    设置导出的excel数据
    CI框架, 参数验证
  • 原文地址:https://www.cnblogs.com/jialanyu/p/13224512.html
Copyright © 2011-2022 走看看