I am unable to delete a filegroup. I am getting the standard error: "The filegroup '~~~~' cannot be removed because it is not empty." I have been searching the internet, and still cannot find the answer. The server version is Microsoft SQL Server 2019.
I have gone through both of these very thoroughly:
Things that I have scanned to see if there is any association to the filegroup:
- files : 0
- allocation_units : 0
- indexes : 0
- partition schemes : 0
- partition functions : 0
- partitions : 0
I have also run DBCC CHECKFILEGROUP and it shows nothing as well. I am really very confused. Can someone help me figure out what else could be the thing keeping me from dropping this filegroup?
Full disclosure, I am using a module I wrote:
https://github.com/tcartwright/tcdbtools/blob/main/docs/Invoke-DBSafeShrink.md
The module performs the following steps:
- creates a temporary file and filegroup
- moves clustered indexes, non-clustered indexes, LOBS, and heaps to the new filegroup
- shrinks the original filegroup
- moves all of the original objects back to the origin filegroup
- removes the temporary file group
As part of moving the LOBs I am using this trick from Kimberly Tripp to move them: https://www.sqlskills.com/blogs/kimberly/understanding-lob-data-20082008r2-2012/
EDIT: I think I have figured out what is blocking the drop, but I cannot figure out how to fix it. This query:
SELECT * FROM sys.[tables] AS [t] WHERE [t].[lob_data_space_id] IN (
SELECT [ds].[data_space_id] FROM sys.[data_spaces] AS [ds] WHERE [ds].[name] <> 'PRIMARY'
)
returns a table that does not have any associated LOB data in the allocation units. Nor can I figure out how to get rid of this. I have:
- dropped and recreated the PK for this table
- rebuilt all of the indexes on the table and
None of which helped.