Recently at my work due low free space on a LUN I was forced to rebuild few indexes on a different filegroup (which resides on a different LUN). I wanted to list all user objects belong to a single filegroup including size. Did not find a query online with everything I needed. So I wrote this one and wanted to share.
--Run this in the context of database that you are working on SELECT FileGroup = FILEGROUP_NAME(a.data_space_id) , TableName = OBJECT_NAME(p.object_id) , IndexName = i.name , 8 * SUM(a.used_pages) AS 'Size(KB)' , 8 * SUM(a.used_pages) / 1024 AS 'Size(MB)' ,…