how to create a data base with only .MDF and .LDF from the existing Database

Answered 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
     
     Answered Has Code
    First empty the files using the command
    DBCC SHRINKFILE(<<LogicalFileName>> ,EMPTYFILE )
    --This would take a time depending on the size of your database.
    --and data on the secondary file
    Then drop the ndf files

    Satheesh


  • Tuesday, February 12, 2013 9:09 AM
     
     Answered Has Code

    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

    SqlAndMe.com