SQL Server log recovery method (handle drop and truncate) _mssql

Source: Internet
Author: User
Tags getdate microsoft sql server mssql mssqlserver
--1
Use master
Backup Database Logtest
To Disk= ' D:\\Program Files\\Microsoft SQL Server\\mssql10. Mssqlserver\\mssql\\backup\\logtest.bak '
With format

--2
Use Logtest
CREATE TABLE table_1 (Id int, test varchar (max))
Insert Table_1 (Id,test) VALUES (1, ' 3333 ');
Insert Table_1 (Id,test) VALUES (2, ' 4333 ');
Insert Table_1 (Id,test) VALUES (3, ' 5333 ');
Use master

--2.1
WAITFOR DELAY ' 00:00:05 '
Go
Use Logtest
TRUNCATE TABLE Table_1
Select GETDATE ()
Use master

--3
Use master
Backup LOG Logtest
To Disk= ' D:\\Program Files\\Microsoft SQL Server\\mssql10. Mssqlserver\\mssql\\backup\\logtest_log.bak '
With format

--4
--declare @dt datetime
--select @dt =dateadd (Ms,-1800,getdate ())
--select @dt
Restore Database Logtest
From disk = ' D:\\Program files\\microsoft SQL Server\\mssql10. Mssqlserver\\mssql\\backup\\logtest.bak '
With REPLACE

RESTORE LOG Logtest
From disk= ' D:\\Program Files\\Microsoft SQL Server\\mssql10. Mssqlserver\\mssql\\backup\\logtest_log.bak '
With stopat= ' 2009-10-26 12:38:57.133 '
Go
Related Article

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.