Friday, April 27, 2007

SQL Server - Clearing/Emptying a Datafile and Removing It

If you have more than one datafile and you'd like to get rid of one, you can clear the data out and remove the file. Here's how:

-----------------------------------------
Moving Data Out of a Datafile
-----------------------------------------

DBCC SHRINKFILE ('[logicalFileName]', EMPTYFILE )

-----------------------------------------
Monitoring the Move of Data
-----------------------------------------

use PADBCC showfilestats

------------------------------
Removing the Datafile
------------------------------

use master
ALTER DATABASE PA REMOVE FILE "[LogicalFileName]"

No comments: