Thursday, 24 February 2011

TSQL : Removing a filegroup

Check no objects sit on the filegroup.
(If they do, then remove them)
SELECT i.*
FROM sys.indexes i
LEFT JOIN sys.filegroups AS fg
ON fg.data_space_id = i.data_space_id
WHERE fg.name = 'myfilegroup'

When all objects are gone, remove the file...
ALTER DATABASE mydatabase
REMOVE FILE mydatabaseFile

When the file has gone, remove the filegroup...
ALTER DATABASE mydatabase
REMOVE FILEGROUP mydatabaseFileGroup

No comments: