Database Research & Development

  • Home
  • NoSQL
    • NoSQL
    • Cassandra
  • Databases
    • Database Theory
    • Database Designing
    • SQL Server Coding Standards
    • SQL Server
    • PostgreSQL
    • MySQL
    • Greenplum
    • Linux
  • Interviews
    • SQL Server Interviews
    • MySQL Interviews
    • SQL Puzzles
  • DBA Scripts
    • SQL Server DBA Scripts
    • PostgreSQL DBA Scripts
    • MySQL DBA Scripts
    • Greenplum DBA Scripts
  • Home
  • Blog Archives !
  • (: Laugh@dbrnd :)
  • Contact Me !
sqlserverinterviews
Home 2017 March SQL Server: Fix – Error 5042 The file ‘FileName’ cannot be removed because it is not empty

SQL Server: Fix – Error 5042 The file ‘FileName’ cannot be removed because it is not empty

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

Mar 12, 2017Anvesh Patel
SQL Server: How to repair corrupted Clustered Index using REPAIR_REBUILD optionSQL Server: Reasons for Error 17204 FCB::Open failed: Could not open file
Comments: 3
  1. Aurelio
    March 25, 2018 at 9:29 pm

    Hello there, You’ve done a great job. I’ll
    definitely digg it and personally recommend to
    my friends.

  2. Radhika
    July 24, 2018 at 9:44 am

    helpful and working

  3. Ranjit Kumar
    February 15, 2019 at 1:03 pm

    DBCC command helped solve the problem indeed, thank you!

Anvesh Patel
Anvesh Patel

Database Engineer

March 12, 2017 SQL ServerAnvesh Patel, Data File, database, database research and development, dbrnd, error 5042, Filegroup, move table, SQL Query, SQL Server, SQL Server Administrator, SQL Server Error, SQL Server Monitoring, SQL Server Performance Tuning, SQL Server Programming, SQL Server Tips and Tricks, TSQL
About Me!

I'm Anvesh Patel, a Database Engineer certified by Oracle and IBM. I'm working as a Database Architect, Database Optimizer, Database Administrator, Database Developer. Providing the best articles and solutions for different problems in the best manner through my blogs is my passion. I have more than six years of experience with various RDBMS products like MSSQL Server, PostgreSQL, MySQL, Greenplum and currently learning and doing research on BIGData and NoSQL technology. -- Hyderabad, India.

About DBRND !

dbrnd

This is a personal blog (www.dbrnd.com).

Any views or opinions represented in this blog are personal and belong solely to the blog owner and do not represent those of people, institutions or organizations that the owner may or may not be associated with in professional or personal capacity, unless explicitly stated.

Feel free to challenge me, disagree with me, or tell me I’m completely nuts in the comments section of each blog entry, but I reserve the right to delete any comment for any reason whatsoever (abusive, profane, rude, or anonymous comments) - so keep it polite.

The content of this website is protected by copyright. No portion of this website may be copied or replicated in any form without the written consent of the website owner.

Recent Comments !
  • Anvesh Patel { Sure will do... } – May 27, 12:43 PM
  • Anvesh Patel { Great... } – May 27, 12:41 PM
  • Anvesh Patel { Great... } – May 27, 12:39 PM
  • Anvesh Patel { Great... } – May 27, 12:36 PM
  • Anvesh Patel { Great... } – May 27, 12:28 PM
  • Anvesh Patel { Great... } – May 27, 12:27 PM
  • Anvesh Patel { Great... } – May 27, 12:16 PM
  • Older »
Follow Me !
  • facebook
  • linkedin
  • twitter
  • youtube
  • google
  • flickr
© 2015 – 2019 All rights reserved. Database Research & Development (dbrnd.com)
Posting....