You may have faced situations when you need to restore a SQL Server database, but the restoration fails because a connected user prevents SQL Server from acquiring the required exclusive mode.
The T-SQL script below will kill all active sessions by switching immediately to exclusive mode. you’ll then be able to restore the db (or perform any other operation requiring exclusive mode), before switching back to multi-user mode. Continue reading