获得所有表的表记录,和使用空间的SQLexec 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 ##'
例如设置了
char(2000)这种大类型的字段.
但其实数据只有很少,大量的空间别' '(空格)占用了.
例如设置了
char(2000)这种大类型的字段.
但其实数据只有很少,大量的空间被' '(空格)占用了.
获得所有表的表记录,和使用空间的SQLexec 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 ##'
database_size unallocated_space
5183.24MB 0.52MB
reserved data index_size unused
5296688KB 3979648KB 1296784KB 20256KB