Renaming .LDF to .NDF File

  • By accident on one of the databases instead of adding a LDF file an NDF file was added with an extension .LDF

    The files was added as a data file however has the extention of .LDF.

    What is best approach to rename this file as .NDF?

    Will this work?

    - Dettach the db

    - Move the file to new location (currently sitting a diff drive)

    - rename the file from .LDF to .NDF on the new location

    - Attach the file as .NDF

  • That should work.

    I assume when you attach, you are attaching the MDF/LDF and new NDF at the same time.

  • Steve Jones - SSC Editor (1/14/2013)


    That should work.

    I assume when you attach, you are attaching the MDF/LDF and new NDF at the same time.

    That is correct. My only concern though is to change the extension from .LDF to .NDF. I dont know what are effects of doing that.

  • No effect. The extensions have no bearing on the files' purpose or use. They are set to mdf/ndf/ldf only for convention.

  • Steve Jones - SSC Editor (1/14/2013)


    No effect. The extensions have no bearing on the files' purpose or use. They are set to mdf/ndf/ldf only for convention.

    Great!! Appreciate your help.

  • ALTER DATABASE with the MOVE option will likely be easier. That changes the name in the system catalog, then you just take the DB offline, change the extensions in Windows Explorer and bring the DB back online.

    As for extensions, this works without a hitch...

    CREATE DATABASE [Silly] ON PRIMARY

    ( NAME = N'Silly', FILENAME = N'D:\Develop\Databases\Silly.doc' )

    LOG ON

    ( NAME = N'Silly_log', FILENAME = N'D:\Develop\Databases\Sillylog.txt' )

    SQL doesn't care what the file extensions are.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Will give it a try. Thanks.

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply