Quantcast
Channel: Welcome to the Database World... » Subhro Saha
Viewing all articles
Browse latest Browse all 18

SQL Server: Removing Secondary Data File from Database !!

$
0
0

Today I want to show you how we can remove secondary data file from a database, now to do this, we need to first move the data from that file to other files in the same filegroup.

In below example, we will remove the Test_DB1 file from TestDB database.

Let us first get the details of all the files in our TestDB database:

Datafile_info

In almost all cases, the file that we would want to remove will have some data that needs to be transferred to other files before we can remove this. To move the data we can use the below command:

USE TestDB
GO
DBCC SHRINKFILE (‘Test_DB1′, EMPTYFILE);

Now to remove the Test_DB1 file from TestDB database we will run the below command:

Remove_File

There is no need to restart SQL server for this to take effect. We can verify that file has been dropped by again getting the details of files in TestDB database:

Datafile_info_1

I hope you enjoyed this post.

Cheers,

Subhro Saha


Viewing all articles
Browse latest Browse all 18

Trending Articles