Linchi Shea recently asked whether people were using database snapshots or not. The consensus seems to be that they’re used during testing and rarely in production.
-- "begin tran"
/*
declare @cmd nvarchar(max)
select @cmd = N'use <dbname,,> exec sys.sp_helpfile'
exec sp_executesql @cmd
*/
CREATE DATABASE <dbname,,>_Snapshot ON
( NAME = datafile, FILENAME = 'C:\Temp\<dbname,,>_Snapshot.ss' )
AS SNAPSHOT OF <dbname,,>
-- "rollback"
/*
select spid from sys.sysprocesses where dbid = db_id('<dbname,,>') and spid > 50
*/
USE master
RESTORE DATABASE <dbname,,> FROM DATABASE_SNAPSHOT = '<dbname,,>_Snapshot';
GO
DROP DATABASE <dbname,,>_Snapshot;
GO
-- "commit"
DROP DATABASE <dbname,,>_Snapshot

