SQL Server: How to attach / repair a detached / damaged database?

前端 未结 2 1376

A database server crashed. I was able to get the mdf and the log file and I am trying to mount it on another server. I don\'t have backup as it was a development database.

2条回答
  •  失恋的感觉
    2020-12-11 09:59

    You can try a workaround. In short:

    1. Create a dummy DB with the same name (may need to remove the real DB first, save the original files or rename then).
    2. Take the dummy off line (detach and (set offline or stop the SQL service)).
    3. Delete dummy files, replace then with the real DB files.
    4. Try to re-attach de DB

    Edit

    As by OP comment note you also can need to rebuild the log (if you lost transactions)

    1. ALTER DATABASE [MyDatabase ] REBUILD LOG ON (NAME=’MyDatabaseLog’,FILENAME=’D:\Microsoft SQL Server\YourDataPath\Data\Logfile.ldf’)

      and put the DB in multiple users log (taking the DB off can require you to put it in single use mode)

    2. ALTER DATABASE [nomdb] SET MULTI_USER

    For all the gore details you can refer to the Paul Randal Article

    (Note in this article the author uses EMERGENCY MODE to (attempt) repair the transaction log)

    I already used it with success but depending on the extent of the damage or others details it can be a impossible task. Consider restoring a backup.

    Note this stunts are fine in a development server but you really need to plan (and drill) for disaster recovery in a prodution server.

提交回复
热议问题