x
login about faq Site discussion (meta-askssc)

How do I remove a file from a filegroup?

Seeder question: I have a file in a filegroup which was created in the wrong place, so I need to remove it and add it back in the right place. However, SQL Server tells me that I cannot remove the file because it has data in it. I cannot take the database off-line completely because it is in constant use. How do I go about removing and adding this file in the right place?

more ▼

asked Oct 28 '09 at 09:56 AM in Default

Matt Whitfield gravatar image

Matt Whitfield ♦♦
29.2k 56 63 87

(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

You need to run DBCC SHRINKFILE with the EMPTYFILE clause, to move data from the file into other files in the same filegroup.

SQL will then prevent any more data being written to that file. You will then be able to use ALTER DATABASE to remove that file.

Alternatively, you can do this from SSMS. This MSDN article takes you through the steps

more ▼

answered Oct 28 '09 at 10:09 AM

Kev Riley gravatar image

Kev Riley ♦♦
46.1k 38 43 69

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments



Facebook logo Follow Ask SSC on Facebook
Find Ask SSC on Google+
linkedin logo Find us on LinkedIn

Topics:

x913
x28
x24

asked: Oct 28 '09 at 09:56 AM

Seen: 2179 times

Last Updated: Oct 28 '09 at 09:56 AM

Copyright © 2002-2012 Simple Talk Publishing. All Rights Reserved. If you have any queries, please contact the site administrators.
Ask SQL Server Central is a community service provided by Red Gate.