sql-serverfilegroup

How can I delete a file of the primary filegroup (SQL Server)


I have a database with a lot of tables and I created a new file in the primary filegroup, I haven't inserted any new data yet but when I try to delete this new file, I get this error

The File ‘newfile’ Cannot be Removed Because it is Not Empty

How can I delete this file?


Solution

  • ok, the solution was as Mitch Wheat indicated in the link that he showed. I had to empty the file using:

    DBCC SHRINKFILE(newfile,EMPTYFILE)
    

    then it can be eliminated using:

    ALTER DATABASE DBNAME REMOVE FILE newfile