查询SQL SERVER所有表记录数和体积大小

来源:互联网 发布:中医网络教育本科 编辑:程序博客网 时间:2024/05/18 01:42
declare aaa  cursor for
select  table_name from information_schema.tables WHERE  TABLE_type='BASE TABLE' order by table_name
open aaa
declare @tb varchar(255)
fetch next from aaa into @tb
while @@fetch_status=0
begin

    exec(' select    '+''''+@tb+''''+' TBNM,(select count(*) from '+@tb+' ) cnt,ltrim(str(sum(reserved) * (select d.low from master.dbo.spt_values d  where d.number = 1 and d.type = ''E'') / 1024.,15,0) +'' '' + ''KB'')  ' 
            +'    +''/''+  ltrim(str(sum(used) * (select d.low from master.dbo.spt_values d  where d.number = 1 and d.type = ''E'') / 1024.,15,0) +'' '' + ''KB'') used              '
            +'    from sysindexes                    
        where indid in (0, 1, 255)                        
        and id = (select  id from sysobjects   
        where id = object_id('+''''+@tb+''''+'))  ')


fetch next from aaa into @tb
end
close aaa
deallocate aaa
原创粉丝点击