SQL Server Performance Forum – Threads Archive
Dropping file from PRIMARY filegroup
My primary filegroup was growing too big so i decided to create a new filegroup and transfer most of the tables over there. But, the primary filegroup was still at 50 GB of size in a RAID 1 container, so I decided to create a new file for PRIMARY in a RAID 10 container, and I proceeded to execute: DBCC SHRINKFILE (1, EMPTYFILE) RTFM says it will empty the file in order to drop it from the database. Sure it did transfer the tables from the 50 GB file to the new file. So I proceeded to drop old 50 GB file: ALTER DATABASE [DB_NAME] REMOVE FILE [PRIMARY_FILE_1] I get this error: Server: Msg 5020, Level 16, State 1, Line 1The primary data or log file cannot be removed from a database. But that does not make sense because the PRIMARY filegroup is still in place with now 2 files. I just want to keep the new one and drop the old one. I cannot even shrink it. Any clues?
Check if there is any statistics in Primary, because that could be one of the razons. Luis Martin
Moderator
SQL-Server-Performance.com All postings are provided “AS IS†with no warranties for accuracy.
That will make sense if we are moving to a different filegroup, but I want to keep the filegroup and just change the files inside it (migrating from old to new). In any case, where can I search for filegroup statistics?
This scrip will help: select si.rows as ‘filas’, SO.Name as Tabla, SI.name as ‘Index’, SFG.groupname as ‘Filegroup’
from sysobjects as SO
join sysindexes as SI
on SO.Id = SI.id
join sysfilegroups as SFG
on SI.GroupId = SFG.GroupId
order by si.rows desc, SO.Name , SI.name, SFG.GroupName Luis Martin
Moderator
SQL-Server-Performance.com All postings are provided “AS IS†with no warranties for accuracy.
The SQL was helpful but I can only see the objects within each FILEGROUP. My problem is this: PRIMARY FILEGROUP has 2 files: File 1: 50 GB
File 2: 20 GB I issued: DBCC SHRINKFILE (1, EMPTYFILE)
in order to move all that from File 1 into File2. I just want to drop File1 and keep File2 but I get this error: Server: Msg 5020, Level 16, State 1, Line 1
The primary data or log file cannot be removed from a database. The file is still 50 GB and I need to free up the space. It does not work. Thanks Oscar
Ok, now I understand.
You can’t drop file1 and keep file2, because both belong to Primary.
One way is to create a new filegroup , move file2 to new one and then delete both file1 and file2 Luis Martin
Moderator
SQL-Server-Performance.com All postings are provided “AS IS†with no warranties for accuracy.
Hi Oscar,<br /><br />also moved here from SQL Server Central? [<img src=’/community/emoticons/emotion-1.gif’ alt=’

Hi Frank, yes I moved from SQL Server Central (not mozilla firefox friendly plus their always sign-in policy). It seems than I cannot drop any file related to the Primary file group. I am recreating all the clustered primary keys now so they are stored in another filegroup. Then I will see If at least I can shrink them.
]]>