Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
USE master;
GO
IF EXISTS (SELECT 1 FROM sys.databases d WHERE d.name = 'RestoreTest')
DROP DATABASE RestoreTest;
GO
CREATE DATABASE RestoreTest
ON (NAME = 'RestoreTest_Primary', FILENAME = 'C:\temp\RestoreTest_Primary.mdf')
LOG ON (NAME = 'RestoreTest_Log', FILENAME = 'C:\temp\RestoreTest_Log.ldf');
GO
ALTER DATABASE RestoreTest SET RECOVERY FULL;
BACKUP DATABASE RestoreTest TO DISK = 'NUL:';
GO
BACKUP DATABASE RestoreTest TO DISK = 'C:\temp\RestoreTest-full.bak' WITH INIT;
USE RestoreTest
GO
CREATE SCHEMA copy1;
GO
USE master;
GO
BACKUP DATABASE RestoreTest TO DISK = 'C:\temp\RestoreTest-copy-1.bak' WITH COPY_ONLY, INIT;
GO
USE RestoreTest
GO
CREATE SCHEMA copy2;
GO
USE master;
GO
BACKUP DATABASE RestoreTest TO DISK = 'C:\temp\RestoreTest-copy-2.bak' WITH COPY_ONLY, INIT;
GO
USE RestoreTest
GO
CREATE SCHEMA diff;
GO
USE master;
GO
BACKUP DATABASE RestoreTest TO DISK = 'C:\temp\RestoreTest-diff-1.bak' WITH DIFFERENTIAL, INIT;
GO
RESTORE DATABASE RestoreTest FROM DISK = 'C:\temp\RestoreTest-full.bak'
WITH NORECOVERY
, REPLACE;
GO
RESTORE DATABASE RestoreTest FROM DISK = 'C:\temp\RestoreTest-diff-1.bak'
WITH RECOVERY;
GO
RESTORE DATABASE RestoreTest FROM DISK = 'C:\temp\RestoreTest-copy-2.bak'
WITH NORECOVERY
, REPLACE;
GO
RESTORE DATABASE RestoreTest FROM DISK = 'C:\temp\RestoreTest-diff-1.bak'
WITH RECOVERY;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment