I need to remove some old files from a production DB, these files are parts of partitioned table. So, the steps were following – I deleted data that theoretically were kept there by partition function (all data from 2007).
Then I merge partition function for that year:
ALTER PARTITION FUNCTION pfPeriod() MERGE RANGE (2007);
Then, I wanted to remove file and filegroup:
ALTER DATABASE mydatabase REMOVE FILE tbProperty2007
ALTER DATABASE mydatabase REMOVE FILEGROUP fgProperty2007
- all by the book.
I’m getting the error:
The file ‘tbProperty2007’ cannot be removed because it is not empty.
The filegroup ‘fgProperty2007’ cannot be removed because it is not empty.
I’ve done this procedure before (for 2005, 2006) and the reason why files wouldn’t remove (for another table) was the index – it was kept in one of the files (I accidentally created index in the partitions of the table). After I recreated index in another filegroup – I could delete file and filegroup without any trouble.
Anyway, this time I recreated indexes in another filegroups, and still – I can’t delete the file and filegroup.
So, can anybody give me an idea how can I see the contents of the *.ndf file, or why the file wouldn’t delete ? please )
P.S. May be it’s a bug of sql server 2012 – I was able to delete files on the sql server 2005, but I can’t do it on 2012.
Use a query like this:
This will show you which indexes are hosted on which data space. You can see if you have a non-partitioned index or table in the filegroup
fgProperty2007.You can also use a query like following to figure out if any partitioning scheme still uses the filegroup: