codebrothers.net :: Home  >  Matthias Denkmaier
User: Guest  Login
Matthias Denkmaier
C# - what else?
Blog search:  
How to: Display current database and object size

I am often asked how to determine the current database size from SQL code.

 

SQL Server gives you the system stored procedure sp_spaceused which does exactly this.

 

To retrieve the current size of your database you could execute

 

exec sp_spaceused

 

in SQL Server Management studio or in the SQL Server console and you should get a resultset containing the current total rows count, the reserved disk space, the current space used by data and the space used by indexes.

 

If you want to know the facts about a specific database object like a table you could execute the statemenmt:

 

exec sp_spaceused ’<your_tabgle_name>’

 

where <your_table_name> is the common table name of the desired table.

 

The resultset will contain only facts about the specified database object.

 

You could use the information to automatically shrink or expand your database disk files (if your sql server is not configured to do it itself yet!)  or you could also hunt possible "space wasters" in you database!

 

Hope this helps!

 

 

Share this post: Email it!
Posted:  10/8/2007 6:58:00 AM  by  mdenkmaier
Tags:  SQLHow to
Comments are not allowed on this item!