No logs, only MDF files how to recover the database

Source: Internet
Author: User
Tags execution log microsoft sql server mssql create database
Recovery | data | Database for a variety of reasons, if we only back up the MDF file, then recovery is a very troublesome thing.
If your MDF file is generated by the current database, then it is a fluke that you may be able to recover the database using sp_attach_db or sp_attach_single_file_db, but there will be a hint of a message device activation error similar to the following. The physical filename ' C:\Program Files\Microsoft SQL Server\mssql\data\test_log.ldf ' may be incorrect.
Created named ' C:\Program Files\Microsoft SQL Server\mssql\data\test_log. LDF ' new log file. However, if your database files are replicated from other computers, unfortunately, perhaps the above approach will not work. You might get the following error message server: Message 1813, Level 16, State 2, line 1
Failed to open new database ' test '. The CREATE DATABASE will terminate.
Device activation error. Physical filename ' D:\test_log. LDF ' may be wrong. What do we do? Don't worry, here are some examples of recovery options.
A We use the default method to create a database (such as test) for recovery use. Can be built in SQL Server Enterprise Manager.
B Deactivate the database server.
C Delete the log file test_log.ldf the database you just generated, overwriting the database data file you just generated with the database MDF file you want to recover test_data.mdf.
D Start the database server. You will see that the state of the database test is suspect. No action can be made on this database at this time.
E. Setting the database allows direct operating system tables. This action allows you to select the database server in SQL Server Enterprise Manager, right-click, select Properties, and select the Allow direct modifications to system directories on the server Settings page. You can also use the following statement to implement it. Use master
Go
sp_configure ' allow updates ', 1
Go
Reconfigure with override
Go F. Set test to Emergency Repair mode update sysdatabases set status=-32768 where dbid=db_id (' test ') can now be in SQL Server Enterprise Manager inside See the database in "read-only \ suspect \ offline \ Emergency mode" can see the table inside the database, but only the system table
G The following performs a real recovery operation, rebuilding the database log file DBCC REBUILD_LOG (' Test ', ' C:\Program Files\Microsoft SQL Server\mssql\data\test_log.ldf ') execution , if you experience the following prompt information:
Server: Message 5030, Level 16, State 1, line 1
Failed to lock the database to perform the operation.
DBCC execution completed. If DBCC prints an error message, contact your system administrator.
Indicates that your other program is using the database, and if you have just opened the system table of the test library using SQL Server Enterprise Manager in step F, then quit SQL Server Enterprise Manager.
The prompt for completion should resemble the following:
Warning: Log of database ' Test ' has been rebuilt. The consistency of the transaction has been lost. DBCC CHECKDB should be run to verify physical consistency. You will have to reset the database options, and you may need to delete the extra log files. Data Recovery SQL database repair password recovery SQL database recovery hard drive bad road repair file restore SQL Server repair file repair RAID data restore SQL database repair RAID disk array SQL restore SQL Server recovery hard disk data recovery hard drive bad repair hard Disk Data Repair Data repair
DBCC execution completed. If DBCC prints an error message, contact your system administrator.
When you open the SQL Server Enterprise Manager, you will see that the state of the database is "for dbo use only." You can now access the user table inside the database.
H. Verify database consistency (can be omitted) DBCC CHECKDB (' test ') generally performs the following results:
CHECKDB found 0 allocation errors and 0 consistency errors (in the database ' test ').
DBCC execution completed. If DBCC prints an error message, contact your system administrator.
I. Set the database to a normal state sp_dboption ' test ', ' dbo use ', ' false ' if there is no error, then congratulations, you can now normal the recovery of the database.
J In the final step, we will restore the "allow direct modifications to the system directory" set in step e. Because the ordinary direct operating system table is a more dangerous thing. Of course, we can recover in SQL Server Enterprise Manager, or we can use the following statement to complete sp_configure ' allow updates ', 0
Go
Reconfigure with override
Go

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.