Skip to content

Instantly share code, notes, and snippets.

@jahanson
Created September 30, 2013 18:39
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 jahanson/6768153 to your computer and use it in GitHub Desktop.
Save jahanson/6768153 to your computer and use it in GitHub Desktop.
Restores a database from a .bak file.
USE [master]
ALTER DATABASE [Portal_Sandbox] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
RESTORE DATABASE [Portal_Sandbox]
FROM DISK = N'C:\Portal93013.bak'
WITH FILE = 1,
MOVE N'Portal' TO N'D:\Data Files\Portal_sandbox.mdf',
MOVE N'Portal_log' TO N'D:\Data Files\Portal_sandbox_log.ldf',
NOUNLOAD, REPLACE, STATS = 5
GO
@jahanson
Copy link
Author

Runs on Microsoft SQL 2008 R2.

@jahanson
Copy link
Author

Backup to file command.

BACKUP DATABASE Portal
TO DISK = 'C:\Portal93013.bak'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment