sp_spaceused is system stored procedure. It provides number of rows and space used information. For example to get space used information for [Sales.SalesOrderDetail] in AdventureWorks database.
USE AdventureWorks GO EXEC sp_spaceused [Sales.SalesOrderDetail] GO
As it returns 6 columns.
- [Name] is name of table that we provided as parameter
- [rows] is number of rows in that table
- [reserved] is total space that is allocated to this table and its indexes
- [data] is amount of space used by data in the table
- [index_Size] is amount of space used by indexes in the table
- [unused] is amount of space that is allocated but currently not in use by table
data + index_size + unused = reserved
If no parameter is provided to sp_spaceused, it will generate space statistics for whole database overall. To make more use we may use sp_spaceused with sp_MSforEachDB or sp_MSforEachTable.