MSSQLServer methods for recovering LDF file data _mssql

Source: Internet
Author: User
Tags mssqlserver rollback management studio sql server management sql server management studio
Our important data is stored in the MDF file, if the LDF file is missing, the MDF file is not lost, then the data can also be restored. If the LDF file is not lost, the MDF file is lost and the LDF file is complete and can also provide some means to restore the data.
Description of the phenomenon
The problem we're facing now is that for WTLOG_2008_M12 this database, only the MDF file and the LDF file are missing, the database is not in SQL Server Management Studio, and an error is also appended.
Solving method
(1) in SQL Server Management Studio Delete the state of recovery pending (that is, the loss of LDF) problem database (that is, should not be in the database management)
(2) Rename the old MDF file. For example, change to Wtlog_2008_m12_bak.mdf.
(3) Rebuild a new database, the name and the missing database exactly the same, for example, if the name of the Wtlog_2008_m12,ldf file for WTLOG_2008_M12, the database prompts the error, said the logical name already exists, but the file can not find, The LDF file here is named Wtlog_2008_m12_log. Note that the location of the new MDF is the same as the location of our old MDF files. The location of the LDF file is chosen in the final position you want to store (this is the restored LDF file you want).
(4) Shut down the SQL Server service and rename the new MDF (Wtlog_2008_m12.mdf) (for example, Wtlog_2008_m12___.mdf), old MDF (wtlog_2008_m12_ BAK.MDF) name back to the original name (Wtlog_2008_m12.mdf).
(5) Open the SQL Server service, connect to the database, execute the following statement, if the error, check whether to connect to the database, or there are other processes attached to the database.
Copy Code code as follows:

ALTER DATABASE WTLOG_2008_M12 SET emergency
ALTER DATABASE WTLOG_2008_M12 set Single_user with rollback immediate
ALTER DATABASE WTLOG_2008_M12 rebuild log on (NAME=WTLOG_2008_M12, filename= ' D:/watcher/database/wtlog_2008_m12.ldf ')
ALTER DATABASE WTLOG_2008_M12 SET Multi_user with rollback immediate

(6) At this point, the MDF and LDF names are wtlog_2008_m12, remove the extra MDF file.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.