This article is half-done without your Comment! *** Please share your thoughts via Comment ***
Recently, I shared an interesting article on the move of your table from one filegroup to another file group by moving only clustered index in SQL Server.
SQL Server: Move your Table from one File Group to another File Group
I got one comment, and one of my readers faced error like “Error 5042 The file ‘FileName’ cannot be removed because it is not empty” while deleting an old file group/data file.
In this post, I am sharing a quick fix of the Error 5042.
The solution is to shrink your empty file before deleting an actual. You can use EMPTYFILE option in DBCC SHRINKFILE to remove all junk data of a file.
1 |
DBCC SHRINKFILE(File_Name,EMPTYFILE) |
After that, you can remove a file from the database using below ALTER command.
1 |
ALTER DATABASE Database_Name REMOVE FILE File_Name |