Skip to content

Instantly share code, notes, and snippets.

@EricCote
Created November 1, 2017 20:38
Show Gist options
  • Save EricCote/b77b9203930ac2178ee79a43d8fd145d to your computer and use it in GitHub Desktop.
Save EricCote/b77b9203930ac2178ee79a43d8fd145d to your computer and use it in GitHub Desktop.
USE [master];
CREATE DATABASE AdventureWorks_Snapshot_1nov2017
ON ( NAME = N'AdventureWorks',
FILENAME = N't:\snap.mdf' )
AS SNAPSHOT OF AdventureWorks;
GO
-------------------------------------
USE AdventureWorks;
SELECT * FROM Person.CountryRegion;
DELETE FROM Person.CountryRegion
WHERE CountryRegionCode LIKE 'Y%';
SELECT * FROM Person.CountryRegion;
INSERT INTO AdventureWorks.Person.CountryRegion
SELECT s.*
FROM AdventureWorks_Snapshot_1nov2017.Person.CountryRegion AS S
LEFT JOIN AdventureWorks.Person.CountryRegion AS C
ON S.CountryRegionCode=c.CountryRegionCode
WHERE C.CountryRegionCode IS NULL;
SELECT * FROM Person.CountryRegion;
-------------------------
USE master;
RESTORE DATABASE AdventureWorks FROM
DATABASE_SNAPSHOT = 'AdventureWorks_Snapshot_1nov2017';
GO
DROP DATABASE AdventureWorks_Snapshot_1nov2017;
 
 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment