Skip to content

Instantly share code, notes, and snippets.

@LitKnd
Created January 31, 2017 22:51
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 LitKnd/46b260a9a88188729ecab8affd0a796a to your computer and use it in GitHub Desktop.
Save LitKnd/46b260a9a88188729ecab8affd0a796a to your computer and use it in GitHub Desktop.
Sample code to restore the free WideWorldImporters Sample Database
/* Download the WideWorldImporters sample database from Microsoft's GitHub page:
This file contains sample TSQL to restore the file WideWorldImporters-Full.bak
Notes & Warnings:
This will BLOW AWAY any existing database named WideWorldImporters.
Adjust the location of the backup file to the location you stored it on your test instance.
This is suitable for dedicated test instances only.
*/
use master;
GO
/* If the database exists, kick everyone out */
IF DB_ID('WideWorldImporters') IS NOT NULL
BEGIN
ALTER DATABASE WideWorldImporters SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
END
GO
/* Restore - and replace if it exists */
RESTORE DATABASE WideWorldImporters
FROM DISK='S:\MSSQL\Backup\WideWorldImporters-Full.bak'
WITH REPLACE,
STATS=10;
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment