how to create a data base with only .MDF and .LDF from the existing Database
-
Tuesday, February 12, 2013 7:14 AM
We have a database with One .mdf file ,8 .ndf files and one lof file.
Now we want to create a database with only .mdf and .ldf from that existing db without secondary files.
could you please suggest me the options
All Replies
-
Tuesday, February 12, 2013 7:30 AM
First empty the files using the commandDBCC SHRINKFILE(<<LogicalFileName>> ,EMPTYFILE )
Then drop the ndf files
--This would take a time depending on the size of your database.
--and data on the secondary file
Satheesh
- Edited by Satheesh Variath Tuesday, February 12, 2013 7:36 AM
- Proposed As Answer by SQL_Learn Tuesday, February 12, 2013 11:17 AM
- Marked As Answer by Allen Li - MSFTModerator Friday, February 22, 2013 2:36 AM
-
Tuesday, February 12, 2013 9:09 AM
You can not do it that way. All data files are required when attaching a database only log file can be re-created.
You need to attach database using all files. After that you can drop the additional .ndf files from database as Sateesh suggested.
To remove a file you can use below command:
ALTER DATABASE [DatabaseName] REMOVE FILE [FileName]
- Vishal
- Proposed As Answer by vr.babu Tuesday, February 12, 2013 9:20 AM
- Marked As Answer by Allen Li - MSFTModerator Friday, February 22, 2013 2:36 AM

