Restore the SQL Server database to a certain time point through Logs
Source: Internet
Author: User
Restore the SQL Server database to a certain time point through logs: 2008/02/11 A. M. -- prerequisites: the database model cannot be "simple"; otherwise, it cannot be recovered. -- Create database dbgo -- back up the database to disk = 'C: \ dB. bak 'with formatgo -- create a test table create table dB. DBO. tb_test (id int) -- delay 1 second, and then perform subsequent operations (this is because the time precision of SQL Server is up to 3% seconds, without delay, this operation may fail to be restored to the time point.) waitfor delay '00: 00: 01' go -- assume that the database is deleted by mistake. DBO. tb_test: Drop table dB. DBO. tb_test -- save the table deletion TIME select dt = getdate () into # Go -- after the delete operation, the table dB cannot be deleted. DBO. tb_test -- The following shows how to restore the accidentally deleted table dB. DBO. tb_test -- first, back up transaction logs (transaction logs can be restored to the specified time point) backup log dB to disk = 'C: \ db_log.bak 'with formatgo -- next, we need to restore the full backup first (the restoration log must be performed on the basis of the full backup) Restore database DB from disk = 'C: \ dB. bak 'with replace, norecoverygo -- restore the transaction log before the delete operation (the time here corresponds to the previous Delete time, and earlier than the deletion time declare @ DT datetimeselect @ dt = dateadd (MS,-20, DT) from # -- get the restore log DB from disk = 'C: \ db_log.bak 'with recovery, stopat = @ dtgo -- Query earlier than the time when the table is deleted, check whether the table resumes select * from DB. DBO. tb_test/* -- result: Id ----------- (the number of affected rows is 0) -- */-- test successful go -- delete the test environment.
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.