• 查看并分析数据表所占的空间


    --1.新增TEMP TABLE
    create   table   #temptable   
    ([name] varchar(50),[rows] bigint,resverved varchar(50),data varchar(50),index_size varchar(50),unused varchar(50))  
    
    --2.执行查询结果
    select 'insert into #temptable exec sp_spaceused '''+name+'''' 
    from sysobjects where objectproperty(id,'IsUserTable')=1
    
    --3. 方便查看
    update #temptable 
    set resverved=left(resverved,charindex(' ',resverved)-1),
    data=left(data,charindex(' ',data)-1),
    index_size=left(index_size,charindex(' ',index_size)-1),
    unused=left(unused,charindex(' ',unused)-1)
    
    --4.查询结果
    select * from #temptable  
    order by cast(resverved as bigint) desc,cast(data as bigint) desc
    ---5. 为了方便比较,汇总
    select convert(char(5),sum(cast(data as bigint))/1024/1024)+'GB' 
    from #temptable
    
    
    select convert(char(5),sum(cast(unused as bigint))/1024)+'MB' 
    from #temptable
    
    select convert(char(5),sum(cast(resverved as bigint))/1024)+'MB' 
    from #temptable
    
    ---有了上面的结果,对每个表进行容量回收,清楚垃圾数据,还可以考虑分离数据库。
    
    
    --drop table #temptable
  • 相关阅读:
    Linux 文件隐藏属性-创建文件默认权限
    Linux 文件权限管理
    Linux 用户管理_用户相关配置文件详解
    Linux 压缩包管理
    vim 编辑器高级用法
    Linux ll查看文件属性详解-软硬链接详解
    安卓学习28
    安卓学习27
    安卓学习26
    安卓学习25
  • 原文地址:https://www.cnblogs.com/GerryGe/p/5114024.html
Copyright © 2020-2023  润新知