Created
November 3, 2015 23:49
-
-
Save ngbrown/d8adda7430400a671771 to your computer and use it in GitHub Desktop.
Determine table row count and sizes of full database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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