Size of Table including Indexes:
This SQL query will provide the size (in KB) of each table including all the indexes on that table:
Size of each Index
This SQL query will provide the size of index in the database:
This SQL query will provide the size (in KB) of each table including all the indexes on that table:
SELECT t.[Name] AS TableName, p.[rows] AS [RowCount], SUM(a.total_pages) * 8 AS TotalSpaceKB, SUM(a.used_pages) * 8 AS UsedSpaceKB FROM sys.tables t INNER JOIN sys.indexes i ON t.OBJECT_ID = i.object_id INNER JOIN sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id INNER JOIN sys.allocation_units a ON p.partition_id = a.container_id WHERE t.is_ms_shipped = 0 AND i.OBJECT_ID > 255 GROUP BY t.[Name], p.[Rows] ORDER BY t.[Name]
Size of each Index
This SQL query will provide the size of index in the database:
SELECT i.[name] AS IndexName, t.[name] AS TableName, SUM(s.[used_page_count]) * 8 AS IndexSizeKB FROM sys.dm_db_partition_stats AS s INNER JOIN sys.indexes AS i ON s.[object_id] = i.[object_id] AND s.[index_id] = i.[index_id] INNER JOIN sys.tables t ON t.OBJECT_ID = i.object_id GROUP BY i.[name], t.[name] ORDER BY i.[name], t.[name]
Comments
Post a Comment
Thanks for your comment. In case of any concerns, please contact me at er.ashishsharma@outlook.com