欢迎来到福编程网,本站提供各种互联网专业知识!
您的位置:网站首页 > 数据库 > MsSql

sqlserver 日志恢复方法(搞定drop和truncate)

发布时间:2009-10-30 作者: 来源:转载
这是一次数据恢复中,我们老大在Sql中敲的,我这里最想记录的是他优良的代码风格.
--1
use master
backup database logTest
to disk='D:Program FilesMicrosoft SQL ServerMSSQL10.MSSQLSERVERMSSQLBackuplogTest.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 FilesMicrosoft SQL ServerMSSQL10.MSSQLSERVERMSSQLBackuplogTest_log.bak'
with format

--4
--DECLARE @dt datetime
--SELECT @dt=DATEADD(ms,-1800,GETDATE())
--select @dt
restore database logtest
from disk = 'D:Program FilesMicrosoft SQL ServerMSSQL10.MSSQLSERVERMSSQLBackuplogTest.bak'
WITH REPLACE

RESTORE LOG logTest
FROM DISK='D:Program FilesMicrosoft SQL ServerMSSQL10.MSSQLSERVERMSSQLBackuplogTest_log.bak'
with STOPAT= '2009-10-26 12:38:57.133'
GO

相关推荐