Today's script comes to you from London where I am at my head office for my appraisal! Lets hope it goes well π
The below script will provide Index information for all non clustered indexes in a database including the number of records, reserved and used space. All you need to do is change the database context to suit.
----------------------------------------------------------------- Non Clustered Index Information ----------------------------------------------------------------- For more SQL resources, check out SQLServer365.blogspot.com ----------------------------------------------------------------- You may alter this code for your own purposes. You may republish altered code as long as you give due credit. You must obtain prior permission before blogging this code. THIS CODE AND INFORMATION ARE PROVIDED "AS IS" ----------------------------------------------------------------- -- Drop temporary table if exists IF OBJECT_ID('tempDB.dbo.#IndexInfo') IS NOT NULL -- Create temporary table SELECT o.name AS ObjectName, p.partition_number AS PartitionID, a.total_pages * 8 / 1024 AS [Reserved(MB)], a.used_pages * 8 / 1024 AS [Used(MB)] INNER JOIN sys.partitions AS p ON i.[object_id] = p.[object_id] AND i.index_id = p.index_id INNER JOIN sys.allocation_units AS a ON p.partition_id = a.container_id INNER JOIN sys.sysobjects o ON i.[object_id] = o.id WHERE i.name NOT LIKE 'sys%' AND o.name NOT LIKE 'sys%' ORDER BY a.total_pages DESC; -- Return index info with TOTAL SUM(a.total_pages * 8 / 1024) AS [Reserved(mb)], SUM(a.used_pages * 8 / 1024) AS [Used(mb)] INNER JOIN sys.partitions AS p ON i.[object_id] = p.[object_id] AND i.index_id = p.index_id INNER JOIN sys.allocation_units AS a ON p.partition_id = a.container_id INNER JOIN sys.sysobjects o ON i.[object_id] = o.id WHERE o.name NOT LIKE 'sys%' Enjoy!
Chris