Last active
August 29, 2015 14:03
-
-
Save kdarty/f136b413d2f3ce6dda22 to your computer and use it in GitHub Desktop.
Database Analysis Report (SQL Server)
This file contains hidden or 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
--Database Analysis Report for SQL Server | |
--Author: M.Ali | |
--Source: http://stackoverflow.com/questions/19433902/how-to-analyze-tables-for-size-in-a-single-db-using-sql-server | |
SET NOCOUNT ON | |
DBCC UPDATEUSAGE(0) | |
-- DB size. | |
EXEC sp_spaceused | |
-- Table row counts and sizes. | |
CREATE TABLE #t | |
( | |
[name] NVARCHAR(128), | |
[rows] CHAR(11), | |
reserved VARCHAR(18), | |
data VARCHAR(18), | |
index_size VARCHAR(18), | |
unused VARCHAR(18) | |
) | |
INSERT #t EXEC sp_msForEachTable 'EXEC sp_spaceused ''?''' | |
SELECT * | |
FROM #t | |
ORDER BY name, index_size | |
-- # of rows. | |
SELECT SUM(CAST([rows] AS int)) AS [rows] | |
FROM #t | |
DROP TABLE #t |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment