Drop all connections of a database

USE Master;
GO

DECLARE @dbname SYSNAME;
SELECT @dbname =‘ABC_Database’;

DECLARE @spid INT;
SELECT @spid = MIN(SPID) FROM master.dbo.sysprocesses
WHERE dbid = DB_ID(@dbname);

WHILE @spid IS NOT NULL
BEGIN
EXECUTE (‘Kill ‘ @spid);
SELECT @spid = MIN(SPID)
FROM master.dbo.sysprocesses
WHERE dbid = DB_ID(@dbname) AND SPID>@spid;
END

PRINT ‘All connection DROPPED!’;