统计数据库中表格数据行数所占空间和索引情况

 1 set nocount on 
 2 exec sp_MSForEachTable 
 3 @precommand=N'
 4 create table ##(
 5 id int identity,
 6 表名 sysname,
 7 字段数 int,
 8 记录数 int,
 9 保留空间 Nvarchar(20),
10 使用空间 varchar(20),
11 索引使用空间 varchar(20),
12 未用空间 varchar(20))',
13 @command1=N'insert ##(表名,记录数,保留空间,使用空间,索引使用空间,未用空间) exec sp_spaceused ''?''
14         update ## set 字段数=(select count(*) from syscolumns where id=object_id(''?'')) where id=scope_identity()',
15 @postcommand=N'select 
16     id,
17     表名,
18     字段数 列数,
19     (记录数/10000.0) 记录数万,
20     (Convert(bigint,rtrim(Replace(保留空间,''KB'','''')))/1024.0) 保留空间M,
21     (Convert(bigint,rtrim(Replace(使用空间,''KB'','''')))/1024.0) 使用空间M,
22     (Convert(bigint,rtrim(Replace(索引使用空间,''KB'','''')))/1024.0) 索引使用空间M,
23     (Convert(bigint,rtrim(Replace(未用空间,''KB'','''')))/1024.0) 未用空间M
24  from ## a order by 使用空间M desc;
25  drop table ##'
26 set nocount off
View Code

相关文章:

  • 2021-06-02
  • 2022-01-13
  • 2022-12-23
  • 2021-12-06
  • 2021-09-22
  • 2021-10-24
  • 2022-01-30
  • 2022-01-02
猜你喜欢
  • 2021-12-04
  • 2021-12-04
  • 2021-12-04
  • 2021-07-02
  • 2021-12-03
  • 2022-12-23
  • 2021-11-15
相关资源
相似解决方案