SqlServer database recovery through transaction logs to a specific point in time

ContractedBlock.gif ExpandedBlockStart.gif Code
- create the test database the CREATE DATABASE  Db the GO - database backup the BACKUP DATABASE  Db  the TO DISK = ' C: \ db.bak ' the WITH  the FORMAT the GO - Create Test Table the CREATE TABLE  Db.dbo.TB_test (ID  int ) - - delay of 1 second, and then subsequent operations (due to the time of maximum precision of SQL Server percent three seconds without any delay, it may be restored to the operating point of failure time) WAITFOR  dELAY  ' 00: 00:01 ' GO - suppose we now misuse removed Db.dbo.TB_test table DROP tABLE  Db.dbo.TB_test - save time deleting tables
 



   



 






 


The SELECT  dt = GETDATE ()  INTO  #
GO - After deletion, found should not delete the table Db.dbo.TB_test - Here is how you recover accidentally deleted this table Db.dbo.TB_test - First, back up the transaction log (use a transaction log to restore to a specified point in time) the bACKUP lOG  Db  the tO DISK = ' c: \ db_log.bak ' the WITH  the FORMAT GO - Next, we must first restore a full backup (restore logs must restore a full backup of foundation performed on) the RESTORE DATABASE  Db  the FROM DISK = ' C: \ db.bak ' the WITH the REPLACE , the NORECOVERY the GO -






   



    


Restore transaction log before the delete operation (here, the time corresponding to the above deletion time, and a little earlier than the time to delete the DECLARE @dt datetime the SELECT @dt = the DATEADD (MS, - 20 is , dt)  the FROM  #   - acquires specific surface deleted time slightly earlier time rESTORE LOG  Db  the FROM DISK = ' c: \ db_log.bak ' the WITH  the rECOVERY, the STOPAT = @dt GO - inquiries about, watch whether to restore the SELECT * the FROM  Db.dbo.TB_test / * - results : ID           -----------  (number of rows affected 0 rows) - * / - test is successful
  
 
   



  









GO - Finally, delete the test environment we do DROP DATABASE  Db DROP TABLE  #


 
 

Reproduced in: https: //www.cnblogs.com/Spring/archive/2009/05/20/1467812.html

Guess you like

Origin blog.csdn.net/weixin_34159110/article/details/93932502