How to restore the database from MDF and LDF file

  • Hi all,

    I have only one MDF and one LDF files of my database.

    I want to restore the database from these files. How can I do this.

    Any help would be greatly appreciated.

    Thanks in advance,

    Jerin S.

  • You need to attach the database either through SSMS or using the sp_attach_db stored procedure.

    [font="Verdana"]Markus Bohse[/font]

  • Thanks Markus Bohse.

    I could restore the database but there is no tables or stored procedures in the database. It seems it is empty database. Is it because there is no tables and stored procedures in the mdf and ldf files?

    Thanks

    Jerin S.

  • Is it because there is no tables and stored procedures in the mdf and ldf files?

    That would appear to be the case.

    Run the following and see if anything turns up:

    USE [!your database name!]

    SELECT * FROM sysobjects WHERE type IN ('U', 'P')

    SQL BAK Explorer - read SQL Server backup file details without SQL Server.
    Supports backup files created with SQL Server 2005 up to SQL Server 2017.

  • Thanks Ray Mond

    I ran the query you sent in the master database. But it returned nothing.

    Can there be any data in the LDF file?.

    How can I retrieve data from LDF file.

    Thanks,

    Jerin S.

  • You need to run the command in the context of the database you attached, not the master database.

    If your database was cleanly detached, all committed transactions would have been written to the data files (mdf, ndf). You could still take a look inside the transaction log if you want to, using 3rd party tools like ApexSQL Log.

    SQL BAK Explorer - read SQL Server backup file details without SQL Server.
    Supports backup files created with SQL Server 2005 up to SQL Server 2017.

  • jerin (9/5/2008)


    Thanks Ray Mond

    I ran the query you sent in the master database. But it returned nothing.

    Even though you ran it in master, not your own database, you still should have got results of the objects in master.

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

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