The following article is mainly about the correct recovery method for SQL Server log file loss. In actual operation, the loss of SQL Server log files is a very difficult thing. The following articles are mainly for the answer given by this question. The following is the main content description of the main text.
I. Overview
In the application system, the database is often the core part. Once the database is destroyed or damaged, it will bring huge losses, so the management of the database is more and more important. . In the database management and maintenance work, we will inevitably have various errors. This paper studies how to use the MDF file to recover the database when the database SQL Server log file is lost.
Second, the recovery of the database
When the database main data MDF file is intact, how to use the MDF file to recover the database in the case of losing the LDF file? We divide the SQL Server log files into two categories: one is the log with no active transactions, and the other is the log with active transactions. According to different logs, different methods are used to recover the database.
1. Log Recovery Without Active Transactions
When logs with no active transactions are lost, we can easily recover the database directly using MDF files, as follows:
1. Separate the suspected database, use the "detach database tool" in the enterprise manager, or use the stored procedure sp_detach_db to separate the database;
2 use the MDF file to attach the database to generate a new log file, available in the Enterprise Manager The "attach database" tool, or attach the database with the stored procedure sp_attach_single_file_db.
If the database log file contains active transactions, this method can not recover the database from the SQL Server log file loss.
2. Log Recovery with Active Transactions
When the log containing active transactions is lost, the above method will appear "The database and log files do not match, you cannot attach the database". For this In the case, we use the following method:
1 Create a database with the same name AAA, and set it to emergency mode
Stop the SQL Server server;
Move the database master data MDF file
Start SQL Server server, create a new database with the same name AAA;
Stop the SQL Server server and overwrite the removed MDF file;
Start SQL Server Server, set AAA to emergency mode, but by default, the system table can not be modified, you must first set it to be modified, run the following statement:
The following is a code snippet: < Br>
Use Master
Go
sp_configure 'allow updates',1
reconfigure with override
Go
Run the following statement to set the AAA database Emergency mode, that is, the status attribute Sysdatabases AAA database table is set to '37268', it says the AAA database is in emergency mode.
update sysdatabases set status=32768 where hame='AAA'
If no errors are reported, you can do the following.
2Set the database AAA to single-user mode, and check the database
Restart the SQL Server server;
Set the database AAA to single-user mode
Sp_dboption 'AAA', 'single user', 'true'
Run the following statement to check the database AAA
DBCC CHECKDB('AAA')
If there is no big problem You can change the state of the database back.
3Restore the state of the database
Run the following statement to restore the state of the database:
The following is the code snippet:
update sysdatabases set status =28 where name='AAA'
sp_configure 'allow updates',0
reconfigure with override
Go
If there are no big problems, Refresh the database, the database AAA will appear in front of you, but the recovery work has not been completed yet, the database still can not work, but also the following processing, in order to truly recover.
4Using DTS import and export wizard, import database AAA into a new database BBB
Create a new database BBB;
Right click BBB, select IMPORT function, open Import Wizard;
Target Source Select "Copy Objects and Databases Between SQL Server Databases" so that table structures, data views and stored procedures can be imported into BBB
Replace the BBB library with the original AAA library.
At this point, the database AAA is fully restored.
SQL Server log file loss is a very dangerous thing, it is very likely that your database is completely destroyed. Recovery of SQL Server databases is done by log files, so it is important to ensure the existence of log files anyway. In order to make our database foolproof, it is best to use a variety of backup methods, so we must pay attention to the management and maintenance of the database.
The print servers web interface The print server is one of the Windows Server 2
In the work, we often encounter a server in order to meet the needs of business access, there are tw
is creative, there is limitless possibilities! During the summer vacation, many college friends who
Increasingly junk spam has become a cancer on the Internet. Although most email a
Take Apache 2.2 as an example: Mod
Graphical tutorial for configuring Php+Mysql+zend under IIS
Linux server front-end error tips and meanings
VPN Server Setup Guide under Windows 2003
Windows 2003 build Apache PHP MySQL environment experience sharing
Solve the description of "Event ID (487) (in the resource (Zend Optimizer) can not be found" problem
Windows Virtual Server Backup Two Methods
Digital Campus Solution Based on Linux Operating System
How DNS Server Works Attack Basics
RAID is mature. Disk Redundancy Array Technology Resolution
Linux with Apache one IP multiple sites multiple domain configuration method
Modify the DPI setting method of the login interface of Win 8 system
How does the Win10 system clear the browser cache?
Win8 system driver update tutorial
How does Win10 correctly display Apple iPhone7 to take photos
How to remove Microsoft Pinyin input method in Windows 10
Win10 th2 official version re-launched installation card in 44% of the problem remains unresolved
How does Win10 open the event viewer? How to use Win10 Event Viewer
Win7 system can not receive the system important update message how to do
Lenovo notebook Win7 system how to achieve the computer sound of the internal record
How does Win10 see if the driver is normal? Win10 update driver graphic tutorial