MSSQL: Drop all active connections to a database

In Microsoft SQL Server you can drop all active connections to a database, prior to restoring it for example, by simply taking the database offline and bringing it back online again immediately.

USE master
GO

ALTER DATABASE 
@databaseName
SET OFFLINE WITH ROLLBACK IMMEDIATE
ALTER DATABASE 
@databaseName
SET ONLINE

Comments

Popular posts from this blog

Enabling SNMP on an ASUS RT-N66U

Ansible on Ubuntu 18.04 on WSL

Debugging multiple PHP projects with VS Code and Laragon