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

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:

name AS LogicalName
,sys.database_files.physical_name AS PhysicalName

By Phil Steffek

Phil Steffek is a professional sumo wrestler who is hoping to represent the U.S. in the next Olympics. During the off season Phil is a Data Architect working on transactional databases, data warehouse implementations, and all aspects of business intelligence. Also, Phil is not really a sumo wrestler. You can get to know a bit more about my non-sumo doings by checking out my LinkedIn Page

Leave a comment

Your email address will not be published.