Blog

SQL Server Combine MDF Files – The Easy Way

Do you need to combine or merge two data files (MDF or NDF)?  There are a number of complicated options available or you can use the two lines of code below to do the trick... It's up to you.  This method works with both SQL Server 2005 and SQL Server 2008.

USE DataBaseName
GO

DBCC SHRINKFILE(LogicalNameOfFileToRemove, EMPTYFILE)
ALTER DATABASE DataBaseName REMOVE FILE LogicalNameOfFileToRemove

If you don't know the logical name of your MS SQL Server files use the following T-SQL query:

SELECT
name AS LogicalName
,sys.database_files.physical_name AS PhysicalName
FROM
sys.database_files

Tags: , , , , , , ,

No comments yet.

Leave a Reply