Permalink
Cannot retrieve contributors at this time
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
37 lines (28 sloc)
923 Bytes
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
/* | |
Will give the size of tables and indexed and number of rows of each table. | |
This allow to understand how the size is used inside a database | |
alexis.comte@capit.net | |
*/ | |
CREATE PROCEDURE [dbo].[p_tableAllocation] | |
AS | |
BEGIN | |
SELECT o.name | |
, SUM(reserved_page_count) * 8 / 1024 AS [reserved space (Mb) ] | |
, SUM(used_page_count) * 8 / 1024 AS [index space (Mb) ] | |
, SUM(CASE | |
WHEN(index_id < 2) | |
THEN(in_row_data_page_count + lob_used_page_count + row_overflow_used_page_count) | |
ELSE lob_used_page_count + row_overflow_used_page_count | |
END) * 8 / 1024 AS [data space (Mb)] | |
, SUM(CASE | |
WHEN(index_id < 2) | |
THEN row_count | |
ELSE 0 | |
END) AS [Rows] | |
FROM sys.dm_db_partition_stats AS s | |
INNER JOIN sysobjects AS o | |
ON s.object_id = o.id | |
GROUP BY o.name | |
ORDER BY 2 DESC; | |
END; | |
GO | |