0

I am working on cleaning data saved in SQL filegroups monthly , where I delete data for one month and then shrink the data filegroup to save space, noting that filegroup is based on date, each month has its' own filegroup.

But this time after deletion done , I noticed there still data in filegroup where the rows are not zero as a result of below query , but I can't determine what are the rows saved there. The shrink didn't work because the free space is not 100%.

So my question is how I can know what is still saved in specific filegroup ?

```
use dhpo

SELECT

FileGroup = FILEGROUP_NAME(a.data_space_id) ,

TableName = OBJECT_NAME(p.object_id) ,

IndexName = i.name ,

           p.rows,

8 * SUM(a.used_pages) AS 'Size(KB)' ,

8 * SUM(a.used_pages) / 1024 AS 'Size(MB)' ,

8 * SUM(a.used_pages) / 1024 / 1024 AS 'Size(GB)'

FROM

sys.allocation_units a

INNER JOIN sys.partitions p

ON  a.container_id = CASE WHEN a.type IN ( 1 , 3 ) THEN p.hobt_id

                      ELSE p.partition_id

                 END

AND p.object_id > 1024

LEFT JOIN sys.indexes i

ON  i.object_id = p.object_id

AND i.index_id = p.index_id


where FILEGROUP_NAME(a.data_space_id)='filegroupName'

GROUP BY

a.data_space_id ,

p.object_id ,

i.object_id ,

           p.rows,

i.index_id ,

i.name

ORDER BY

           OBJECT_NAME(p.object_id),

FILEGROUP_NAME(a.data_space_id) ,

SUM(a.used_pages) DESC; ```
  • Viewing the tables in SSMS objext explorer will give you row counts and space used for each, that might give you a clue? – Stu Aug 12 '21 at 08:06
  • yes it gave me row counts but for all partitions of the table , not for specific filegroup. although I need to know what are those rows . – Ala' Mohsen Aug 12 '21 at 08:12

0 Answers0