How does mssqlserver restore ldf file data

Source: Internet
Author: User

Our important data is stored in the MDF file. If the LDF file is lost and the MDF file is not, the data can be restored. If the LDF file is not lost, the MDF file is lost, and the LDF file is complete, you can also restore the data by some means.
Symptom description
The problem we need to face now is that for the wtlog_2008_m12 database, only the MDF file is lost while the LDF file is lost. This database is not available in SQL Server Management Studio, and an error will be prompted when attaching the database.
Solution
(1) deletion of a problematic database in the SQL Server Management Studio state as Recovery Pending (that is, the LDF is lost) (if any, it should not be in the Database Management)
(2) Rename the old MDF file. For example, change it to wtlog_2008_m12_bak.mdf.
(3) create a new database with the same name as the lost database. For example, if the name of the wtlog_2008_m12 or LDF file is wtlog_2008_m12, the database prompts an error saying that the logical name already exists, however, the file cannot be found. The LDF file here is named wtlog_2008_m12_log. Note that the position of the new MDF is the same as that of the old MDF file. the location of the LDF file here is the final location you want to store (this is the restored LDF file ).
(4) disable the SQL Server service and rename the new MDF (wtlog_2008_m12.mdf) (for example, change it to wtlog_2008_m12 ___. mdf), old MDF (wtlog_2008_m12_bak.mdf) is named back to the original name (wtlog_2008_m12.mdf ).
(5) Enable the SQL Server service, connect to the database, and execute the following statement. If an error is reported, check whether the database is connected or if other processes are connected to the database.
Copy codeThe Code is 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) In this case, both mdf and ldf are named wtlog_2008_m12. Delete the excess mdf file.

Related Article

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.