您好,我是小DAI,专注于数据库管理员相关的技术问答,请问有什么可以帮您?

sp_spaceusage

语法

“help”操作语法:


sp_spaceusage 'help'[, 'all']

sp_spaceusage 'help'[, {'display' | 'display summary' | 'report' | 'report summary' | 'archive'}[, {'table' | 'index' | 'tranlog'}]]

“display”操作语法:


sp_spaceusage 'display summary [using unit= {KB | MB | GB | PAGES}]', 
	{'table' | 'index'},<name>
	[, <where_clause>[, order_by[,<command>]]]

sp_spaceusage 'display [using unit= {KB | MB | GB | PAGES} ]',
	{'table' | 'index'}, <name> 
	[, <select_list> 
	[, <where_clause>[, order_by[, <command>]]]]

sp_spaceusage 'display [using unit={KB | MB | GB | PAGES}]', 
     'tranlog'[, <name>[, <select_list>[, <where_clause> [, order_by]]]]

sp_spaceusage 'display [using unit=<unit>]', 
     'sysimrslogs' [,{'sysimrslogs'|NULL}
     [,<select_list> [,<where_clause> [,order_by]]]] 

display database 操作语法:


sp_spaceusage 'display [summary] [using unit={KB | MB | GB | PAGES}]', 'database' 
     [, <db_name>]

sp_spaceusage 'display [using unit={KB | MB | GB | PAGES}]', 'database' [, <db_name>]

“archive”操作语法:


sp_spaceusage 'archive [using {<using_item> [,<using_item>]
', {'table' | 'index'}, <name>[, <where_clause>[, <command>]]

sp_spaceusage 'archive [using {<using_item> [,<using_item>]...} ]
', 'sysimrslogs' [,{'sysimrslogs'|NULL}[, <where_clause>]]

sp_spaceusage 'archive [using {<using_item> [,<using_item>]...} ]
', 'syslogs' [,{'syslogs'|NULL} [, <where_clause>]]

<using_item> = { unit={ KB | MB | GB | PAGES } 
	| dbname=<database_name> | prefix=<string>}

“report”操作语法:


sp_spaceusage 'report summary [using {<using_item> [,<using_item>]...}', 
	{'table' | 'index'}, <name> 
	[, <where_clause> [, order_by[, <from_date> [, <to_date>]]]]

sp_spaceusage 'report [using {<using_item> [,<using_item>]...}', 
	{'table' | 'index'}, <name> 
	[,<select_list>[, <where_clause> [, order_by[,<from_date> [,<to_date>]]]]]

sp_spaceusage 'report [using {<using_item> [,<using_item>]...}', 
	'tranlog'[, <name> 
	[,<select_list>[, <where_clause>[, order_by 
	[,<from_date>[, <to_date>]]]]]]

<using_item> = { unit={ KB | MB | GB | PAGES } 
	| dbname=<database_name> | prefix=<string>}

参数

help

显示完整的 sp_spaceusage 语法。help <action> 显示受支持的各项操作的语法。

display

显示指定对象的当前空间使用信息。database 允许您在位于任何其它数据库中时显示任何数据库的信息。这表示,当前可以在 user_db 数据库中工作,并显示 sybsystemprocs 数据库的使用信息。

display summary

显示指定对象的当前空间使用信息摘要。

archive

将空间使用报告存档到表中。如果存档表尚不存在,sp_spaceusage 将创建一个。新数据将附加到现有数据中。使用 <using> 子句可为存档表名和存档表所在的数据库指定前缀。存档需要您启用 select into/bulkcopy/pllsort 数据库选项。

report

根据以前存档的数据,报告指定对象的空间使用信息。该输出与 display 操作相同。包括可选的 using 子句,用以指定存档表。

report summary

根据以前存档的数据,报告指定对象的空间使用信息摘要。该输出与 display summary 操作相同。包括可选的 using 子句,用以指定存档表。

<using_item>

为存档表指定单位、存档数据库名称和前缀字符串。可以使用千字节 (KB)、兆字节 (MB)、千兆字节 (GB) 和页表示 <unit> 大小。缺省情况下,<unit> 大小为 KB,当前数据库是存档数据库,并且不使用前缀字符串。

<name>

是实体的名称。根据实体类型,可以包括由多个部分组成的名称,如 <owner_name.table_name><owner_name.table_name.index_name>。对于实体类型 tranlog、syslogs 和 sysimrslogs,名称必须为 syslogs、sysimrslogs 或 NULL。在由多个部分组成的名称中,每个部分都允许使用模式指示符,以支持在一次传递中报告多个对象。

<select_list>

是以逗号分隔的一组列,要在输出列中选择这些列供 display 和 report 操作使用。使用 * 将包括输出中的所有列。可使用 alias=<name> 表示法对列进行重命名。

<where_clause>

是应用于结果集的过滤器。与 display、report 或 archive 操作一起使用可选择性地过滤掉不必要的数据。

order_by

按排序顺序返回指定列中的查询结果。

<command>

在收集空间使用信息之前为限定对象对所选实体(表、列等)运行的命令。支持以下命令:update statistics、update table statistics 和 update index statistics

<from_date>

指定您感兴趣的时间范围的开始时间。

<to_date>

指定您感兴趣的时间范围的结束时间。

示例

示例 1

显示 display 操作的简要说明、语法和用法信息:


sp_spaceusage 'help', 'display'

Display the space usage information for an entity in the current database.

Usage:
sp_spaceusage 'display', 'database' [, '<dbname>' ]

sp_spaceusage 'display', {'table'|'index'}, <name>
                        [,<select_list> [,<where_clause> [, order_by [,<command>]]]]

sp_spaceusage 'display summary', {'table'|'index'}, <name>
                        [,<where_clause> [, order_by [, <command>]]]

sp_spaceusage 'display', 'syslogs' [,{'syslogs'|NULL}
                        [,<select_list> [, <where_clause> [, order_by]]]]

sp_spaceusage 'display', 'sysimrslogs' [,{'sysimrslogs'|NULL}
                        [,<select_list> [, <where_clause> [,order_by]]]]

For more information, use:
sp_spaceusage 'help', 'display', 'database'
sp_spaceusage 'help', 'display', 'table'
sp_spaceusage 'help', 'display', 'index'
sp_spaceusage 'help', 'display', 'syslogs'
sp_spaceusage 'help', 'display', 'sysimrslogs'

示例 2

显示 titles 表的空间使用摘要:


sp_spaceusage 'display summary', 'table', 'titles'

All the page counts in the result set are in the unit 'KB'.
OwnerName  TableName  Type   UsedPages  RsvdPages  ExpRsvdPages  PctBloatRsvdPages
---------  ---------  ----   ---------  --------   ------------  -----------------
dbo        titles     DATA   6.0        30.0       16.0          87.50
dbo        titles     INDEX  8.0        64.0       32.0          50.00

示例 3

显示 titles 表的空间使用信息:


sp_spaceusage 'display', 'table', 'titles'

All the page counts in the result set are in the unit 'KB'.
OwnerName    TableName    IndId    NumRows    UsedPages    RsvdPages
  ExtentUtil     ExpRsvdPages    PctBloatUsePages     PctBloatRsvdPages
-----------  -----------  ------  -----------  ----------   --------------
  ----------     ------------    ----------------     -----------------
dbo          titles       0       18.0         6.0          30.0
  20.00          16.0            0.0                  87.50 
dbo          titles       1       NULL         4.0          32.0
  12.50          16.0            0.00                 100.00
dbo          titles       2       NULL         4.0          32.0
  12.50          16.0            0.00                 100.00

示例 4

显示 titles 表中名称以 title 开始的索引条目:


sp_spaceusage 'display using unit=MB', 'index', 'titles.title%'

All the page counts in the result set are in the unit 'MB'.
OwnerName  TableName    IndId  IndexName   UsedPages       RsvdPages
  ExtentUtil   ExpRsvdPages     PctBloatUsedPages   PctBloatRsvdPages
--------   --------     -----  ----------  ----------      ---------
  ----------   ------------     -----------------   ----------------
dbo        titles        0     titles      .005859375     .029296875 
  20.00        .015625           0.00               87.50
dbo        titles       1      titleidind  .00390625      .03125                
  12.50        .015625           0.00               100.00
dbo        titles       2      titleind    .00390625      .03125
  12.50        .015625           0.00               100.00
(1 row affected)
(return status = 0)

示例 5

显示 titles 表中名称以 开头的所有索引的空间使用摘要:</p> <div class="code-block"><pre><code> sp_spaceusage 'display summary', 'index', 'titles.title%' </code></pre><button class="copy-btn" onclick="copyCode(this)" title="复制代码"><span class="copy-icon">📋</span><span class="copied-icon">✓</span></button></div> <div class="code-block"><pre><code> All the page counts in the result set are in the unit of 'KB'. OwnerName TableName IndexName IndId UsedPages RsvdPages ExpRsvdPages PctBloatRsvdPages -------- --------- --------- ----- --------- ---------- ------------ ----------------- dbo titles titles 0 6.0 30.0 16.0 46.67 dbo titles titleidind 1 4.0 32.0 16.0 50.00 dbo titles titleind 2 4.0 32.0 16.0 50.00 </code></pre><button class="copy-btn" onclick="copyCode(this)" title="复制代码"><span class="copy-icon">📋</span><span class="copied-icon">✓</span></button></div> <h4>示例 6</h4> <p>显示 titles 表中以<code> <title></code> 开头并且 PctBloatRsvdPages 值小于 50 的所有索引的空间使用摘要:</p> <div class="code-block"><pre><code> sp_spaceusage 'display summary', 'index', 'titles.title%', 'where PctBloatRsvdPages < 50' </code></pre><button class="copy-btn" onclick="copyCode(this)" title="复制代码"><span class="copy-icon">📋</span><span class="copied-icon">✓</span></button></div> <div class="code-block"><pre><code> All the page counts in the result set are in the unit 'KB'. OwnerName TableName IndexName IndId UsedPages RsvdPages ExpRsvdPages PctBloatRsvdPages --------- --------- --------- ----- --------- --------- ---------- ----------------- dbo titles titles 0 6.0 30.0 16.0 46.67 </code></pre><button class="copy-btn" onclick="copyCode(this)" title="复制代码"><span class="copy-icon">📋</span><span class="copied-icon">✓</span></button></div> <h4>示例 7</h4> <p>按 PctBloatRsvdPages 的降序显示 titles 表中 PctBloatRsvdPages 值大于 30 的所有索引的空间使用摘要:</p> <div class="code-block"><pre><code> sp_spaceusage 'display summary', 'index', 'titles.title%', 'where PctBloatRsvdPages > 30', 'order by PctBloatRsvdPages desc' </code></pre><button class="copy-btn" onclick="copyCode(this)" title="复制代码"><span class="copy-icon">📋</span><span class="copied-icon">✓</span></button></div> <div class="code-block"><pre><code> All the page counts in the result set are in the unit 'KB'. OwnerName TableName IndexName IndId UsedPages RsvdPages ExpRsvdPages PctBloatRsvdPages --------- --------- --------- ----- --------- --------- ---------- ----------------- dbo titles titleidind 1 4.0 32.0 16.0 50.00 dbo titles titleind 2 4.0 32.0 16.0 50.00 dbo titles titles 0 6.0 30.0 16.0 46.67 </code></pre><button class="copy-btn" onclick="copyCode(this)" title="复制代码"><span class="copy-icon">📋</span><span class="copied-icon">✓</span></button></div> <h4>示例 8</h4> <p>对 authors 表运行 update table statistics 并以 <code><pages></code> 为单位汇总其空间使用信息:</p> <div class="code-block"><pre><code> sp_spaceusage 'display summary using unit=pages', 'table', 'authors', null, null, null, 'update table statistics' </code></pre><button class="copy-btn" onclick="copyCode(this)" title="复制代码"><span class="copy-icon">📋</span><span class="copied-icon">✓</span></button></div> <div class="code-block"><pre><code> All the page counts in the result set are in the unit 'pages'. OwnerName TableName Type UsedPages RsvdPages ExpRsvdPages PctBloatRsvdPages --------- --------- ---- --------- --------- ------------ ----------------- dbo authors DATA 2.0 16.0 8.0 100.00 dbo authors INDEX 4.0 32.0 16.0 50.00 </code></pre><button class="copy-btn" onclick="copyCode(this)" title="复制代码"><span class="copy-icon">📋</span><span class="copied-icon">✓</span></button></div> <h4>示例 9</h4> <p>显示当前数据库 (pubs2) 的事务日志的空间使用信息:</p> <div class="code-block"><pre><code> sp_spaceusage 'display', 'tranlog' </code></pre><button class="copy-btn" onclick="copyCode(this)" title="复制代码"><span class="copy-icon">📋</span><span class="copied-icon">✓</span></button></div> <div class="code-block"><pre><code> TableName TotalPages UsedPages CLRPagesFreePages PctUsedPages PctFreePages --------- ----------- --------- ----------------- ------------- ----------- syslogs 4096.0 18.0 0.0 1482.0 0.43 36.18 </code></pre><button class="copy-btn" onclick="copyCode(this)" title="复制代码"><span class="copy-icon">📋</span><span class="copied-icon">✓</span></button></div> <h4>示例 10</h4> <p>将当前数据库中 authors 表的空间使用信息存档到缺省表中(对于表和索引,缺省表为 spaceusage_object):</p> <div class="code-block"><pre><code> sp_spaceusage 'archive', 'table', 'authors' </code></pre><button class="copy-btn" onclick="copyCode(this)" title="复制代码"><span class="copy-icon">📋</span><span class="copied-icon">✓</span></button></div> <div class="code-block"><pre><code> Data was successfully archived into table 'pubs2.dbo.spaceusage_object'. </code></pre><button class="copy-btn" onclick="copyCode(this)" title="复制代码"><span class="copy-icon">📋</span><span class="copied-icon">✓</span></button></div> <h4>示例 11</h4> <p>将 authors 表的空间使用信息存档到 pubs3 数据库中的缺省表中(对于表和索引,缺省表为 spaceusage_object):</p> <div class="code-block"><pre><code> sp_spaceusage 'archive using dbname = pubs3', 'table', 'authors' </code></pre><button class="copy-btn" onclick="copyCode(this)" title="复制代码"><span class="copy-icon">📋</span><span class="copied-icon">✓</span></button></div> <div class="code-block"><pre><code> Data was successfully archived into table 'pubs3.dbo.spaceusage_object'. </code></pre><button class="copy-btn" onclick="copyCode(this)" title="复制代码"><span class="copy-icon">📋</span><span class="copied-icon">✓</span></button></div> <h4>示例 12</h4> <p>对 authors 表运行 update table statistics 并将其空间使用信息存档到当前数据库中前缀为 monday_ 的表(此示例中为 monday_spaceusage_object)中:</p> <div class="code-block"><pre><code> sp_spaceusage 'archive using dbname = pubs2, prefix=monday_', 'table','authors', null, 'update table statistics' </code></pre><button class="copy-btn" onclick="copyCode(this)" title="复制代码"><span class="copy-icon">📋</span><span class="copied-icon">✓</span></button></div> <h4>示例 13</h4> <p>将当前数据库的事务日志的空间使用信息存档到 pubs3 数据库的缺省表(对于事务日志,缺省表为 spaceusage_tranlog)中:</p> <div class="code-block"><pre><code> sp_spaceusage 'archive using dbname=pubs3', 'tranlog' </code></pre><button class="copy-btn" onclick="copyCode(this)" title="复制代码"><span class="copy-icon">📋</span><span class="copied-icon">✓</span></button></div> <div class="code-block"><pre><code> Data was successfully archived into table 'pubs3.dbo.spaceusage_tranlog'. </code></pre><button class="copy-btn" onclick="copyCode(this)" title="复制代码"><span class="copy-icon">📋</span><span class="copied-icon">✓</span></button></div> <h4>示例 14</h4> <p>根据当前数据库中的缺省表(对于表或索引,缺省表为 spaceusage_object),详细报告上次存档的 authors 表的空间使用信息:</p> <div class="code-block"><pre><code> sp_spaceusage 'report', 'table', 'authors' </code></pre><button class="copy-btn" onclick="copyCode(this)" title="复制代码"><span class="copy-icon">📋</span><span class="copied-icon">✓</span></button></div> <div class="code-block"><pre><code> All the page counts in the result set are in the unit 'KB'. All the data in the result set are dated 'Jun 15 2013 11:50PM'. OwnerName TableName IndId NumRows UsedPages RsvdPages ExtentUtil ExpRsvdPages PctBloatUsedPages PctBloatRsvdPages --------- --------- ----- ------- --------- --------- ---------- ------------ ----------------- ----------------- dbo authors 0 23.0 4.0 32.0 12.50 16.0 0.00 100.00 dbo authors 1 NULL 4.0 32.0 12.50 16.0 0.00 100.00 dbo authors 2 NULL 4.0 32.0 12.50 16.0 0.00 100.00 </code></pre><button class="copy-btn" onclick="copyCode(this)" title="复制代码"><span class="copy-icon">📋</span><span class="copied-icon">✓</span></button></div> <h4>示例 15</h4> <p>根据 pubs3 数据库中的缺省表,概要报告上次存档的 authors 表的空间使用信息:</p> <div class="code-block"><pre><code> sp_spaceusage 'report summary using dbname=pubs3', 'table', 'authors' </code></pre><button class="copy-btn" onclick="copyCode(this)" title="复制代码"><span class="copy-icon">📋</span><span class="copied-icon">✓</span></button></div> <div class="code-block"><pre><code> All the page counts in the result set are in the unit 'KB'. All the data in the result set are dated 'Jan 17 2013 11:29AM'. OwnerName TableName Type UsedPages RsvdPages ExpRsvdPages PctBloatRsvdPages --------- --------- ---- ---------- -------- ------------ ----------------- dbo authors DATA 4.0 32.0 16.0 100.00 dbo authors INDEX 8.0 64.0 32.0 50.00 </code></pre><button class="copy-btn" onclick="copyCode(this)" title="复制代码"><span class="copy-icon">📋</span><span class="copied-icon">✓</span></button></div> <h4>示例 16</h4> <p>根据当前数据库中的 monday_spaceusage_object 表,报告上次存档的 authors 表的空间使用信息摘要(以兆字节为单位):</p> <div class="code-block"><pre><code> sp_spaceusage 'report summary using prefix=monday_, unit=MB', 'table', 'authors' </code></pre><button class="copy-btn" onclick="copyCode(this)" title="复制代码"><span class="copy-icon">📋</span><span class="copied-icon">✓</span></button></div> <div class="code-block"><pre><code> All the page counts in the result set are in the unit 'MB'. All the data in the result set are dated 'Jan 17 2013 11:29AM'. OwnerName TableName Type UsedPages RsvdPages ExpRsvdPages PctBloatRsvdPages --------- --------- ---- ---------- -------- ------------ ----------------- dbo authors DATA .00390625 .03125 .015625 100.00 dbo authors INDEX .0078125 .0625 .03125 50.00 </code></pre><button class="copy-btn" onclick="copyCode(this)" title="复制代码"><span class="copy-icon">📋</span><span class="copied-icon">✓</span></button></div> <h4>示例 17</h4> <p>根据当前数据库中的缺省表,报告在 2013 年 6 月 9 日或之后存档的、authors 表上所有索引的空间使用信息:</p> <div class="code-block"><pre><code> sp_spaceusage 'report', 'index', 'authors.%', null, null, null, 'Jun 9 2013' </code></pre><button class="copy-btn" onclick="copyCode(this)" title="复制代码"><span class="copy-icon">📋</span><span class="copied-icon">✓</span></button></div> <div class="code-block"><pre><code> All the page counts in the result set are in the unit 'KB'. ArchiveDateTime OwnerName TableName IndId IndexName UsedPages RsvdPages ExtentUtil ExpRsvdPages PctBloatUsedPages PctBloatRsvdPages --------------- --------- --------- ----- --------- ---------- --------- --------- ----------- ---------------- -------------- Jun 9 2013 12:06AM dbo authors 0 authors 4.0 32.0 12.50 16.0 0.00 100.00 Jun 10 2013 12:05AM dbo authors 0 authors 4.0 32.0 12.50 16.0 0.00 100.00 Jun 11 2013 11:35PM dbo authors 0 authors 4.0 32.0 12.50 16.0 0.00 100.00 Jun 9 2013 12:06AM dbo authors 1 auidind 4.0 32.0 12.50 16.0 0.00 100.00 Jun 10 2013 12:05AM dbo authors 1 auidind 4.0 32.0 12.50 16.0 0.00 100.00 Jun 11 2013 11:35PM dbo authors 1 auidind 4.0 32.0 12.50 16.0 0.00 100. Jun 9 2013 12:06AM dbo authors 2 aunmind 4.0 32.0 12.50 16.0 0.00 100.00 Jun 10 2013 12:05AM dbo authors 2 aunmind 4.0 32.0 12.50 16.0 0.00 100.00 Jun 11 2013 11:35PM dbo authors 2 aunmind 4.0 32.0 12.50 16.0 0.00 100.00 (1 row affected) (return status = 0) </code></pre><button class="copy-btn" onclick="copyCode(this)" title="复制代码"><span class="copy-icon">📋</span><span class="copied-icon">✓</span></button></div> <h4>示例 18</h4> <p>根据当前数据库中的缺省表,报告在 2013 年 6 月 10 日与 2013 年 6 月 15 日之间存档的 authors 表的空间使用信息:</p> <div class="code-block"><pre><code> sp_spaceusage 'report', 'table', 'authors', null, null, null, 'Jun 10 2013', 'Jun 15 2013' </code></pre><button class="copy-btn" onclick="copyCode(this)" title="复制代码"><span class="copy-icon">📋</span><span class="copied-icon">✓</span></button></div> <div class="code-block"><pre><code> All the page counts in the result set are in the unit 'KB'. ArchiveDateTime OwnerName TableName IndId NumRows UsedPages RsvdPages ExtentUtil ExpRsvdPages PctBloatUsedPages PctBloatRsvdPages --------------- --------- --------- ----- ------- --------- --------- ---------- ------------ ----------------- -------------- Jun 10 2013 12:05AM dbo authors 0 23.0 4.0 32.0 12.50 16.0 0.00 100.00 Jun 11 2013 11:35PM dbo authors 0 23.0 4.0 32.0 12.50 16.0 0.00 100.00 Jun 13 2013 11:46PM dbo authors 0 23.0 4.0 32.0 12.50 16.0 0.00 100.00 Jun 14 2013 11:46PM dbo authors 0 23.0 4.0 32.0 12.50 16.0 0.00 100.00 Jun 14 2013 11:46PM dbo authors 0 23.0 4.0 32.0 12.50 16.0 0.00 100.00 Jun 10 2013 12:05AM dbo authors 1 NULL 4.0 32.0 12.50 16.0 0.00 100.00 Jun 11 2013 11:35PM dbo authors 1 NULL 4.0 32.0 12.50 16.0 0.00 100.00 Jun 13 2013 11:46PM dbo authors 1 NULL 4.0 32.0 12.50 16.0 0.00 100.00 Jun 14 2013 11:46PM dbo authors 1 NULL 4.0 32.0 12.50 16.0 0.00 100.00 Jun 14 2013 11:46PM dbo authors 1 NULL 4.0 32.0 12.50 16.0 0.00 100.00 Jun 10 2013 12:05AM dbo authors 2 NULL 4.0 32.0 12.50 16.0 0.00 100.00 Jun 11 2013 11:35PM dbo authors 2 NULL 4.0 32.0 12.50 16.0 0.00 100.00 Jun 13 2013 11:46PM dbo authors 2 NULL 4.0 32.0 12.50 16.0 0.00 100.00 Jun 14 2013 11:46PM dbo authors 2 NULL 4.0 32.0 12.50 16.0 0.00 100.00 Jun 14 2013 11:46PM dbo authors 2 NULL 4.0 32.0 12.50 16.0 0.00 100.00 (1 row affected) (return status = 0) </code></pre><button class="copy-btn" onclick="copyCode(this)" title="复制代码"><span class="copy-icon">📋</span><span class="copied-icon">✓</span></button></div> <h4>示例 19</h4> <p>显示使用 pubs2 数据库时有关 sybsystemprocs 的信息(sybsystemprocs 在下方以粗体显示):</p> <div class="code-block"><pre><code> sp_spaceusage 'display using unit=MB', 'database', sybsystemprocs </code></pre><button class="copy-btn" onclick="copyCode(this)" title="复制代码"><span class="copy-icon">📋</span><span class="copied-icon">✓</span></button></div> <div class="code-block"><pre><code> All the page counts in the result set are in the unit 'MB'. TotalPages UsedPages FreePages PctUsedPages PctFreePages DataPages IndexPages LOBPages PctData PctIndex PctLOB ---------- --------- --------- ------------ ------------ --------- ---------- -------- ------- -------- ------ 400.000 123.625 276.375 30.91 69.09 116.203 6.125 0.063 94.00 4.95 0.05 (1 row affected) TableName TotalPages UsedPages CLRPages FreePages PctUsedPages PctFreePages --------- ---------- --------- -------- ---------- ------------ ------------ syslogs 200.0 1.171875 0.0 198.828125 0.58 99.41 (1 row affected) TableType Layer DataPages UsedPages RsvdPages UsedPct ------------- ----------- ---------- ---------- ---------- ------- All Tables All layers 122.359375 123.5625 145.671875 30.89 All Tables Data layer 122.359375 116.734375 131.078125 29.18 All Tables Index Layer 122.359375 6.703125 14.09375 1.68 All Tables LOB Layer 122.359375 .125 .5 0.03 System Tables Data layer 116.109375 116.546875 130.328125 29.14 System Tables Index layer 6.078125 6.671875 13.96875 1.67 System Tables LOB layer .0625 .125 .5 0.03 User Tables Data layer .09375 .1875 .75 0.05 User Tables Index layer .015625 .03125 .125 0.01 User Tables LOB layer NULL NULL NULL NULL </code></pre><button class="copy-btn" onclick="copyCode(this)" title="复制代码"><span class="copy-icon">📋</span><span class="copied-icon">✓</span></button></div> <h4>示例 20</h4> <p>显示顶层的摘要,聚合 tpcc 数据库的数据库范围使用信息:</p> <div class="code-block"><pre><code> sp_spaceusage 'display summary using unit=GB', 'database', tpcc; </code></pre><button class="copy-btn" onclick="copyCode(this)" title="复制代码"><span class="copy-icon">📋</span><span class="copied-icon">✓</span></button></div> <div class="code-block"><pre><code> All the page counts in the result set are in the unit 'GB'. TotalPages UsedPages FreePages PctUsedPages PctFreePages DataPages IndexPages LOBPages PctData PctIndex PctLOB ---------- --------- --------- ------------ ------------ --------- ---------- -------- ------- -------- ------ 87.891 46.476 41.414 52.88 47.12 35.216 11.259 0.000 75.77 24.22 0.00 (1 row affected) TableName TotalPages UsedPages CLRPages FreePages PctUsedPages PctFreePages --------- ---------- ----------------- -------- ------------------ ------------ ------------ syslogs 58.59375 .2289886474609375 0.0 58.364761352539062 0.39 99.60 (1 row affected, return status = 0) </code></pre><button class="copy-btn" onclick="copyCode(this)" title="复制代码"><span class="copy-icon">📋</span><span class="copied-icon">✓</span></button></div> <h3>用法</h3> <p><ul><li>sp_spaceusage 提供当前数据库的表、索引和事务日志的空间使用信息。</p> <p></li></ul><ul><li>在其中存档空间使用数据的数据库必须已启用 <code>sp_dboption ... select into</code>。</p> <p></li></ul><ul><li>如果在存档时不存在存档表,则会创建存档表,否则结果将附加到当前表中。因此,运行 sp_spaceusage 的所有用户都必须在存档数据库中拥有 create table 权限。</p> <p></li></ul><ul><li>在存档或报告数据期间,只有用户所有的表运行 sp_spaceusage 时,才显示存档表考虑的所有索引的空间使用信息(以兆字节为单位)。忽略其他用户拥有的同名表。缺省情况下,对于表或索引,结果会存档至 spaceusage_object 表或根据该表报告结果;对于事务日志,结果会存档至 spaceusage_tranlog 或根据它报告结果。。</p> <p></li></ul><ul><li>在根据存档数据进行报告时,只能将 <code><from_date></code> 和 <code><to_date></code> 参数用于 report 操作。生成报告时,SAP ASE 服务器只使用存档表中指定时间范围内的数据。如果不包括 <code><from_date></code> 或 NULL,SAP ASE 服务器将使用 <code><to_date></code> 之前的所有存档数据。如果不包括 <code><to_date></code> 或 NULL,SAP ASE 服务器将使用当前日期作为 <code><to_date></code> 的值。如果既不包括 <code><from_date></code>,也不包括<code> <to_date></code>,SAP ASE 服务器将使用存档表中的最新数据生成报告。</p> <p></li></ul><ul><li>sp_spaceusage 结果是根据统计数据进行估计的。这些估计的精确性取决于所提供的统计信息。可运行 update statistics 来提高结果的精确性。</p> <p></li></ul><ul><li>'display', 'database' 选项生成聚合的数据库范围空间使用指标,和每个级别(数据、索引、LOB 等)的系统和用户表的空间使用信息摘要。</p> <p></li></ul><ul><li>对于具有大量对象的数据库,display 可能会明显变慢,因为运行它还涉及运行每个对象或索引的执行空间报告函数。在这些情况下,您可以发出 display summary 作为替代以快速检索数据库范围的聚合空间指标。</p> <p></li></ul><ul><li>'display summary', 'database' 选项生成聚合的数据库范围摘要信息,但不调查每个表或每个对象指标的级别。</p> <p></li></ul><ul><li>sp_spaceusage 显示启用内存行存储表的 sysimrslogs 的指标。</li></ul></p> </div> <div class="footer-copyright"> <div class="copyright-info"><a href="../index.html">© 2026 DBASK.CN DBASK.COM.CN</a></div> <div class="icp-info">京ICP备2024098115-2 | 京ICP备2024098115-3</div> </div> </div> </div> </body> </html>