/*============================================================================
  File:     6b_Restoring_Full_TLog_Backups_SpecificPointInTime.sql

  Summary:  This script shows how to restore a database to a 
			specific point in time.

  Date:     April 2018

  SQL Server Version: 2005/2008/2008R2/2012/2014/2016/2017
------------------------------------------------------------------------------
  Written by Erin Stellato, SQLskills.com

  For more scripts and other useful content, go to:
	http://www.SQLskills.com

  This script is intended only as a supplement to demos and lectures
  given by Erin Stellato.  
  
  THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF 
  ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED 
  TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  PARTICULAR PURPOSE.
============================================================================*/

/*
	what does the script look like if generated from the UI?
*/

USE [master];
GO

RESTORE DATABASE [AdventureWorks2017_TEST] 
	FROM  DISK = N'C:\Backups\AW2017_COPY_InitialFull.bak' WITH  FILE = 1,  
	MOVE N'AdventureWorks2017_COPY_Data' TO N'C:\Databases\AW_TEST\AdventureWorks2017_TEST_Data.mdf',  
	MOVE N'AdventureWorks2017_COPY_Log' TO N'C:\Databases\AW_TEST\AdventureWorks2017_TEST_Log.ldf',  
	NORECOVERY,  NOUNLOAD,  STATS = 5;
GO

RESTORE LOG [AdventureWorks2017_TEST] 
	FROM  DISK = N'C:\Backups\AW2017_COPY_TLog1.trn' WITH  FILE = 1,  
	NORECOVERY,  NOUNLOAD,  STATS = 5;
GO

RESTORE LOG [AdventureWorks2017_TEST] 
	FROM  DISK = N'C:\Backups\AW2017_COPY_TLog2.trn' WITH  FILE = 1,  
	NORECOVERY,  NOUNLOAD,  STATS = 5;
GO

--format for STOPAT: 2016-04-01T13:31:40
RESTORE LOG [AdventureWorks2017_TEST] 
	FROM  DISK = N'C:\Backups\AW2017_COPY_TLog3.trn' WITH  FILE = 1,  
	NORECOVERY,  NOUNLOAD,  STATS = 5,  STOPAT = N'2018-04-24T12:05:28';
GO


RESTORE DATABASE [AdventureWorks2017_TEST] WITH RECOVERY;
GO


USE [AdventureWorks2017_TEST];
GO

/*
	CHECK THE DATA
*/
SELECT * FROM [Sales].[SalesOrderDetail]
WHERE [LineTotal] > 10000.00;
GO


SELECT *
FROM [Person].[Person]
WHERE [PersonType] <> 'IN' ;
GO


