Reports the space usage for a table, index, or transaction log and estimates the amount of fragmentation for tables and indexes in a database. The estimates are computed using an average row-length for data and index rows, and the number of rows in a table. You can archive the space usage and fragmentation data for future reporting and trends analysis. sp_spaceusage supports a number of actions, including help, display, archive and report, to indicate the current SAP ASE space usage.
sp_spaceusage 'help'[, 'all']
sp_spaceusage 'help' [, {'display' | 'display summary' | 'report' | 'report summary' | 'archive'} [, {'table' | 'index' | 'tranlog'}]]
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 'archive [ using_clause ]', {'table' | 'index'}, name[,where_clause[,command] ]
sp_spaceusage 'archive [ using_clause ]', 'tranlog' [,name[,where_clause] ]
sp_spaceusage 'report summary [ using_clause ]', {'table' | 'index'}, name [,where_clause [,order_by[,from_date [,to_date]]]]
sp_spaceusage 'report [ using_clause ]', {'table' | 'index'}, name [,select_list[,where_clause [,order_by[,from_date [,to_date]]]]]
sp_spaceusage 'report [ using_clause ]', 'tranlog' [, name [,select_list[,where_clause [,order_by [,from_date [,to_date]]]]]] using_clause = USING using_item [, using_item ...]
using_item = { unit={ KB | MB | GB | PAGES } | dbname=database_name | prefix=string }
sp_spaceusage 'help', 'display'
Display the space usage information for an entity in the current database. Usage: 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', 'tranlog' [,{'syslogs'|NULL} [,<select_list> [,<where_clause> [,<order_by>]]]] For more information, use: sp_spaceusage 'help', 'display', 'table' sp_spaceusage 'help', 'display', 'index' sp_spaceusage 'help', 'display', 'tranlog'
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
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
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)
sp_spaceusage 'display summary', 'index', 'titles.title%'
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
sp_spaceusage 'display summary', 'index', 'titles.title%', 'where PctBloatRsvdPages < 50'
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
1> sp_spaceusage 'display summary', 'index', 'titles.title%', 'where PctBloatRsvdPages > 30', 'order by PctBloatRsvdPages desc'
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
sp_spaceusage 'display summary using unit=pages', 'table', 'authors', null, null, null, 'update table statistics'
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
sp_spaceusage 'display', 'tranlog'
TableName TotalPages UsedPages CLRPagesFreePages PctUsedPages PctFreePages --------- ----------- --------- ----------------- ------------- ----------- syslogs 4096.0 18.0 0.0 1482.0 0.43 36.18
sp_spaceusage 'archive', 'table', 'authors'
Data was successfully archived into table 'pubs2.dbo.spaceusage_object'.
sp_spaceusage 'archive using dbname = pubs3', 'table', 'authors'
Data was successfully archived into table 'pubs3.dbo.spaceusage_object'.
1> sp_spaceusage 'archive using dbname = pubs2, prefix=monday_', 'table','authors', null, 'update table statistics'
sp_spaceusage 'archive using dbname=pubs3', 'tranlog'
Data was successfully archived into table 'pubs3.dbo.spaceusage_tranlog'.
sp_spaceusage 'report', 'table', 'authors'
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 (1 row affected)(return status = 0)
sp_spaceusage 'report summary using dbname=pubs3', 'table', 'authors'
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
sp_spaceusage 'report summary using prefix=monday_, unit=MB', 'table', 'authors'
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
sp_spaceusage 'report', 'index', 'authors.%', null, null, null, 'Jun 9 2013'
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)
sp_spaceusage 'report', 'table', 'authors', null, null, null, 'Jun 10 2013', 'Jun 15 2013'
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)
sp_spaceusage provides space usage information for tables, indexes, and the transaction log of the current database.
The database in which you are archiving the space usage data must have sp_dboption ... select into enabled.
The archive tables are created if they do not already exist at the time of archiving, otherwise the results are appended to the current table. Because of this, any user running sp_spaceusage must have create table permission in the archive database.
While archiving or reporting data, only tables owned by the user running sp_spaceusage are considered for the archive table. Tables with the same name but owned by another user are ignored. By default, the results are archived to or reported from the spaceusage_object table for tables or indexes and spaceusage_tranlog for the transaction log. .
You can use the from_date and to_date arguments only for the report action when reporting from archived data. The SAP ASE server uses only the data in the archive table that falls within the specified time-range when generating the report. If you do not include a from_date or a NULL, the SAP ASE server uses all archived data prior to the to_date. If you do not include a to_date or NULL, the SAP ASE server uses the current date as the value for to_date. If you do not include either the from_date or to_date, the SAP ASE server uses the most recent data in the archive table to generate the report.
sp_spaceusage results are estimated based on statistical data. These estimates are only as good the statistics provided. You can run update statistics to improve the accuracy of the results.
Any user can execute sp_spaceusage to view space usage. However, you may not be able to view certain information about tables that you do not have persmissions to view.