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

Windows 7 - Cisco VPN Client

Enabling SNMP on an ASUS RT-N66U

Making Microsoft Dataverse OData queries using Postman