Skip to content

Instantly share code, notes, and snippets.

@adamvduke
Created October 20, 2010 01:33
Show Gist options
  • Save adamvduke/635585 to your computer and use it in GitHub Desktop.
Save adamvduke/635585 to your computer and use it in GitHub Desktop.
/* Forces exclusive access to a database allowing a restore and subsequently restores the database from a backup file. This will interrupt any existing connections and rollback any in progress transactions. Use at your own risk. */
ALTER DATABASE [database_name] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
RESTORE DATABASE [database_name]
FROM DISK = N'C:\path\to\backup\backupfile.bak'
WITH FILE = 1, KEEP_REPLICATION, NOUNLOAD, REPLACE, STATS = 10
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment