Skip to content

Instantly share code, notes, and snippets.

@daltonjorge
Last active September 25, 2025 23:08
Show Gist options
  • Save daltonjorge/1b9ee926d90943b8823df83db348838c to your computer and use it in GitHub Desktop.
Save daltonjorge/1b9ee926d90943b8823df83db348838c to your computer and use it in GitHub Desktop.
Close existing connections to a SQL Server database #sqlserver #sql #database
-- disconnect all other sessions connected to the database 'syscit'
USE master;
GO
ALTER DATABASE syscit SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
GO
-- drop the database 'syscit' if it exists
IF EXISTS (SELECT name FROM sys.databases WHERE name = N'syscit')
BEGIN
DROP DATABASE syscit;
END
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment