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.