When we restore a database from prod to dev which method is better to disconnect other connection accessing the database? I am on SQL Server 2008r2
1. Change to Single user mode
use masterGoALTER DATABASE MyDB SET SINGLE_USER WITH ROLLBACK IMMEDIATE Go RESTORE DATABASE [MyDB] FROM DISK = N'D:\Restore_Backup\Restore_05042015\DB.bak'WITH FILE = 1, MOVE N'DB'TO N'D:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\MyDB.mdf', MOVE DB_log'TO N'D:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\MyDB_log.ldf', NOUNLOAD, REPLACE, STATS = 10GOALTER DATABASE MyDB SET MULTI_USER Go
2. Take offline the database and restore database
USE masterGOALTER DATABASE MyDBSET OFFLINE WITH ROLLBACK IMMEDIATEGORESTORE DATABASE [MyDB] FROM DISK = N'D:\Restore_Backup\Restore_05042015\DB.bak'WITH FILE = 1, MOVE N'DB'TO N'D:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\MyDB.mdf', MOVE DB_log'TO N'D:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\MyDB_log.ldf', NOUNLOAD, REPLACE, STATS = 10GOALTER DATABASE MyDBSET OFFLINE GO
Which method would assure I will be the only user so I can do the restoration without a problem?