SQL Clone
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Monitor database growth - a better way for sp_spaceused

By Gaby Abed,

This script is for anyone who has had issues in capturing the output from sp_spaceused, which returns two rows of different number of columns, therefore making it hard to capture into a table easily. I ran exec sp_helptext sp_spaceused and found the section where the two rows returned (I'm still confused why there are two select statements, one after the other, that don't have to be separated).

I did not keep the @updateusage portion of sp_spaceused and neither did I try to preserve the table check either via @objname (not needed for my purposes)


UPDATE: Oct 22, 2008 - Had a superflous variable here and there, so just cleaned up the code.

Total article views: 4006 | Views in the last 30 days: 3
Related Articles




spaceused of a table

spaceused query...


SQL Server – Internals of sp_spaceused

This article is an effort to dissect the output of the sp_spaceused stored procedure. Introductio...


sp_spaceused system-stored procedure

You can use the sp_spaceused system-stored procedure to return space usage information about a datab...


Capturing DB Usage stats – sp_spaceused simulation using DMV’s.

SP_SPACEUSED sp_spaceused is one of the system stored procedure used frequently by many dba’s tha...

database size    
sql server 2005