Removing all connections to a microsoft sql server

DECLARE @SQL VARCHAR(8000)

SELECT @SQL=COALESCE(@SQL,”)+’Kill ‘+CAST(spid AS VARCHAR(10))+ ‘; ‘
FROM sys.sysprocesses
WHERE DBID=DB_ID(‘DATABASE_NAME’)

EXEC(@SQL)

Leave a Reply

Your email address will not be published. Required fields are marked *