Saturday, May 18, 2013

SQL Database Size


Database Size
-- Find space used for current database
EXEC sp_spaceused
Below we see that the results for sp_spaceused returns two result sets. The first result set shows a high level view of the database space. With the most important being database size, showing the amount of disk space used for both the data and log files.
The second result set shows the allocation within the database and does not include the log file usage. The total amount is shown under “reserved”. And the Data, Index, and unused spaces are split up to give a good breakdown of what is utilizing the most space.

sp_spaceused database results
Table Size
In order to run this command for a table pass in the table name with schema name enclosed in single quotes.
-- Find space used for specific table
EXEC sp_spaceused 'SalesLT.Address'
Evaluating this output looks similar to the second record set returned by the database results, except we also get the number of rows contained in the table. This number of rows may not be precisely correct because it gets the number by looking at the table statistics instead of doing an actual count of the rows.

No comments:

Post a Comment