Skip to main content

How to kill all user sessions on a DB

Sometimes in SQL you need to delete some rows, delete a Table or the DB. But what if a user is still connected to it. The solution is simple, kill all the sessions on that DB with a simple script: USE master SET NOCOUNT ON DECLARE @DBName varchar(50) DECLARE @spidstr varchar(8000) DECLARE @ConnKilled smallint SET […]