locked
How to create DB back from .mdf and .ldf (data and log file)? RRS feed

  • Question

  • Is that restore or some other process? forgot
    Wednesday, April 22, 2009 11:46 AM

Answers

All replies

    • Proposed as answer by h0xff Wednesday, April 22, 2009 12:20 PM
    Wednesday, April 22, 2009 11:49 AM
  • Hi
    By Running the below query we can attach the database (Considering two files .mdf and .ldf files)

    EXEC 

    sp_attach_db @dbname = N'DatabaseName',
    @filename1
    = N'c:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\DatabaseName_Data.mdf', @filename2 = N'c:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\DatabaseName_log.ldf'

    The path what i have given is default path. It changes based upon where the .mdf and .ldf files are Placed.
    After attaching(Restoring) the Database. We can take Backup from that

    Thanks
    Ramesh.M
    • Proposed as answer by Pinal Dave Wednesday, April 22, 2009 12:32 PM
    Wednesday, April 22, 2009 12:08 PM
  • my mdf file is stored in
    c:\\db\db.mdf


    i want to attach db and keep it here...
    c:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\

    how to do?
    Thursday, April 23, 2009 12:35 PM
  • Is this .mdf Associated Database already there in the SQL Server?
    Or
    We have to create Database by using this .mdf File? Can you please clarify me

    Thanks
    Ramesh.M
    Thursday, April 23, 2009 12:52 PM
  • my mdf file is stored in
    c:\\db\db.mdf


    i want to attach db and keep it here...
    c:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\

    how to do?
    Copy the mdf and ldf files to the directory listed above then attach the database file to your SQL server. 
    http://msdn.microsoft.com/en-us/library/ms190794.aspx
    Thursday, April 23, 2009 9:26 PM