Monday, October 13, 2014

SINGLE_USER Mode Backup RESTORE

This code puts a database in SINGLE_USER mode and runs a backup. This is for when I cannot drop connections fast enough:

ALTER DATABASE [DBName]
SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
RESTORE DATABASE [DBName] FROM DISK =
'C:\Program Files\Microsoft SQL Server\Blahblahblah\MSSQL\Backup\DBName.BAK'
GO

If a DB gets stuck in Single User more:

ALTER DATABASE  [DBName]
SET MULTI_USER
WITH ROLLBACK IMMEDIATE
GO

0 Comments:

Post a Comment

<< Home