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.
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.
After that, you can remove a file from the database using below ALTER command.
ALTER DATABASE Database_Name REMOVE FILE File_Name
Please share your ideas and opinions about this topic with me, your contribution will add true value to this topic.
If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.
If you like this post, then please share it with others.
Please follow dbrnd.com, I will share my experience towards the success of Database Research and Development Activity.
I put up a post every day, please keep reading and learning.
Discover Yourself, Happy Blogging !
Anvesh M. Patel.