Space / usage per table

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

Follow

Get every new post delivered to your Inbox.