zoukankan      html  css  js  c++  java
  • SQL Server查看所有表大小,所占空间

    create table #Data(name varchar(100),row varchar(100),reserved varchar(100),data varchar(100),index_size varchar(100),unused varchar(100)) declare @name varchar(100) declare cur cursor for select name from sysobjects where xtype='u' order by name open cur fetch next from cur into @name while @@fetch_status=0 begin insert into #data exec sp_spaceused @name print @name fetch next from cur into @name end close cur deallocate cur create table #DataNew(name varchar(100),row BIGINT,reserved BIGINT,data BIGINT,index_size BIGINT,unused BIGINT) insert into #dataNew select name,convert(BIGINT,row) as row,convert(BIGINT,replace(reserved,'KB','')) as reserved,convert(BIGINT,replace(data,'KB','')) as data, convert(BIGINT,replace(index_size,'KB','')) as index_size,convert(BIGINT,replace(unused,'KB','')) as unused from #data select * from #dataNew order by data desc DROP TABLE #Data DROP TABLE #dataNew
     

    --主要原理: 

    exec sp_spaceused '表名' --取得表占用空間 
    exec sp_spaceused ''--數據庫所有空間 

    还有一个简单的办法

    SELECT   a.name, b.rows
    FROM      sysobjects AS a INNER JOIN
                     sysindexes AS b ON a.id = b.id
    WHERE   (a.type = 'u') AND (b.indid IN (0, 1))
    ORDER BY b.rows DESC


    pasting
  • 相关阅读:
    单列模式
    经济数据价格走势图(包括纸黄金),可以查看历史
    UVA10010的类似BFS做法
    转:数据结构专项之Hash函数
    ZOJ1709 DFS和BFS两种搜索方法
    HDU1969(二分搜索)
    HDU1045 回溯
    HDU2899(三分搜索)
    安神口中的水题
    HDU2199(二分搜索无限逼近)
  • 原文地址:https://www.cnblogs.com/baozhu/p/9318103.html
Copyright © 2011-2022 走看看