查询SQL数据库中每一个表的大小

--得到数据库中所有表的空间/记录情况 
exec sp_MSForEachTable  @precommand=N' 
create table ##( id int identity, 表名 sysname, 字段数 int, 记录数 int, 保留空间 Nvarchar(10), 使用空间 varchar(10), 索引使用空间 varchar(10), 未用空间 varchar(10))', @command1=N'insert ##(表名,记录数,保留空间,使用空间,索引使用空间,未用空间) exec sp_spaceused ''?''  update ## set 字段数=(select count(*) from syscolumns where id=object_id(''?''))  where id=scope_identity()', @postcommand=N'select * from ## order by id drop table ##'

posted on 2011-06-30 09:45  不悔的青春  阅读(751)  评论(0编辑  收藏  举报

导航