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

Realtek HD Audio speakers and headphones with separate volume

Reformatting a php.ini file with Sublime Text 3 for use with Ansible