Skip to content

Instantly share code, notes, and snippets.

@ngbrown
Created November 3, 2015 23:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ngbrown/d8adda7430400a671771 to your computer and use it in GitHub Desktop.
Save ngbrown/d8adda7430400a671771 to your computer and use it in GitHub Desktop.
Determine table row count and sizes of full database
-- Determine table row count and sizes of full database
-- Inspired from http://stackoverflow.com/a/19916574/25182
SET NOCOUNT ON
DECLARE @TableInfo TABLE (tablename varchar(128), [rows] int, reserved varchar(18), [data] varchar(18), index_size varchar(18), unused varchar(18))
DECLARE @cmd1 varchar(200)
SET @cmd1 = 'exec sp_spaceused ''?'''
INSERT INTO @TableInfo (tablename,[rows],reserved,[data],index_size,unused)
EXEC sp_msforeachtable @command1=@cmd1
SELECT tablename
, [rows]
, Convert(int,Replace([reserved],' KB','')) AS [reservedKB]
, Convert(int,Replace([data],' KB','')) AS [dataKB]
, Convert(int,Replace([index_size],' KB','')) AS [index_sizeKB]
, Convert(int,Replace([unused],' KB','')) AS [unusedKB]
FROM @TableInfo ORDER BY tablename
EXEC sp_spaceused
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment