How to recover database from MDF in SQL Server 2005?

后端 未结 9 419
野性不改
野性不改 2021-01-31 11:20

I have an MDF file and no LDF files for a database created in MS SQL Server 2005. When I try to attach the MDF file to a different SQL Server, I get the following error messa

相关标签:
9条回答
  • 2021-01-31 12:19

    Found a another way that works completely:

    1. Create new database with same name to default database location.
    2. Stop SQL server.
    3. Copy old mdf file to overwrite newly created mdf file and delete new ldf file
    4. Start SQL Server, database will be in emergency mode
    5. Detach the emergency mode database
    6. Copy original ldf file to default database location (where new LDF file as created and deleted under step 3 above.
    7. Attach the database MDF file.

    I got a working database after trying all of the above that failed for me.

    0 讨论(0)
  • 2021-01-31 12:20

    I hope it is easy to do so,

    1. Open SQL Server
    2. Click New Query
    3. Execute the following query

      sp_attach_single_file_db @dbname='dbname',@physname='C:\Database\dbname.MDF'

    Where dbname is you want to show in Object Explorer, where @physname is the local filepath location of your mdf file.

    Hope it will help someone, i done by above, got both structure and also data.

    Tested in Sql Server 2000 and 2008. In Sql Server 2000 it is not working, but works perfectly in 2008.

    0 讨论(0)
  • 2021-01-31 12:21

    have you tried to ignore the ldf and just attach the mdf:

    sp_attach_single_file_db [ @dbname = ] 'dbname' , [ @physname = ] 'physical_name'

    i don't know exactly what will happen to your open transactions (probably just lost), but it might get your data back online.

    -don

    0 讨论(0)
提交回复
热议问题