Space / usage per table
October 28, 2008 Leave a comment
This very short script will loop through all of your (user created) tables and return the number of rows and space used. Very useful indeed.
SET NOCOUNT OFF
DECLARE @tblName VARCHAR(255)
DECLARE tblCursor CURSOR FOR
SELECT name FROM sysobjects WHERE type = ‘U’ ORDER BY name
OPEN tblCursor
FETCH NEXT FROM tblCursor
INTO @tblName
WHILE @@FETCH_STATUS = 0
BEGIN
EXEC sp_spaceused @tblName
FETCH NEXT FROM tblCursor
INTO @tblName
END
CLOSE tblCursor
DEALLOCATE tblCursor