1

I have created files and filegroup under partitioning process. These secondary files have data in them. I want to remove these files as I have deleted the table from the database but I am finding it difficult to remove them. how can I remove them?

3 Answers 3

1

You have to clean the files before removing them.

Using command:

USE [YourDB]
GO
DBCC SHRINKFILE (N'YourFileLogicalName' , EMPTYFILE)

Using SSMS:

enter image description here

Choose your file and turn option: Empty file by migrating the data to other files in the same filegroup.

1

You need to remove all allocations from that filegroup. That includes indexes, tables and partitions that resides on that filegroup. Then you can remove the files and finally the filegroup.

For just a file and to keep other files for the same filegroup (not what I think you're asking about), then you can shrink that file using the EMPTYFILE option and then remove that file.

0

These queries may be helpful to you if you are looking for details in the FG's

--Find partition schema and partition function details on a DB
SELECT t.name AS TableName, ps.name AS PartitionScheme,
ps.data_space_id, pf.name AS PartitionFunction, pf.function_id
FROM sys.TABLES t
JOIN sys.indexes i ON t.object_id = i.object_id
JOIN sys.partition_schemes ps ON i.data_space_id = ps.data_space_id
JOIN sys.partition_functions pf ON ps.function_id = pf.function_id


--To determine what object is on which FG
SELECT o.[name] AS TableName, i.[name] AS IndexName, fg.[name] AS FileGroupName
FROM sys.indexes i
INNER JOIN sys.filegroups fg ON i.data_space_id = fg.data_space_id
INNER JOIN sys.all_objects o ON i.[object_id] = o.[object_id]
WHERE i.data_space_id = fg.data_space_id AND o.type = 'U'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.