EXEC sp_spaceused 表名 可以查询表的数据量和容量等信息,
循环查询数据库下表的的数据量和容量等信息用一下代码:
if exists(select * from tempdb..sysobjects where id=object_id('tempdb..#spaceused'))
begin
drop table #spaceused
end
create table #spaceused (
name varchar(40),
rows char(11),
reserced varchar(18),
date varchar(18),
index_size varchar(18),
unuesd varchar(18)
)
declare @cursor cursor
declare @name varchar(40)
set @cursor = cursor for
select
name
from
sysobjects
where
xtype = 'U'
and name='M_TABLE'
open @cursor
fetch next from @cursor into @name
while @@fetch_status = 0
begin
insert into #spaceused
EXEC sp_spaceused @name
fetch next from @cursor into @name
end
select * FROM #SPACEUSED