Skip to content

Instantly share code, notes, and snippets.

@naradae
Last active December 6, 2021 00:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naradae/99a7358bbb0aae054608455ff7129932 to your computer and use it in GitHub Desktop.
Save naradae/99a7358bbb0aae054608455ff7129932 to your computer and use it in GitHub Desktop.
SQL Snapshot Commands
/*
Instructions:
- Replace CRONUSLIVE with your database name
- Replace 202112031200 with a current timestamp
- Replace the database file names and paths with the names from your database. Use SELECT * FROM sys.database_files to assist with this
- The snapshot must latest be deleted (with DROP DATABASE CRONUSLIVE_snapshot_202112031200), as it continues to be a drain on all transactions in the source database
*/
CREATE DATABASE CRONUSLIVE_snapshot_202112031200 ON (
NAME = [CRONUSLIVE_Data]
,FILENAME = 'D:\SQLData\CRONUSLIVE_snapshot_202112031200.mdf'
) AS SNAPSHOT OF CRONUSLIVE
/*
Instructions:
- Replace CRONUSLIVE_snapshot_202112031200 with your database name. Use SELECT * FROM sys.databases to see all database names
*/
DROP DATABASE CRONUSLIVE_snapshot_202112031200;
/*
Instructions:
- Replace CRONUSLIVE with your database name
- Replace CRONUSLIVE_snapshot_202112031200 with the name of your snapshot. Use SELECT * FROM sys.databases to see all database names
*/
USE master
ALTER DATABASE CRONUSLIVE SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
GO
ALTER DATABASE CRONUSLIVE SET MULTI_USER;
GO
RESTORE DATABASE CRONUSLIVE FROM DATABASE_SNAPSHOT = 'CRONUSLIVE_snapshot_202112031200';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment