Need to kill all processes connected to a given database, say before a database restore where a web app is trying to reconnect?

 

DECLARE @SQL VARCHAR(8000) 

SELECT @SQL=COALESCE(@SQL,”)+’Kill ‘+CAST(spid AS VARCHAR(10))+ ‘; ‘

FROM sys.sysprocesses

WHERE DBID=DB_ID(‘AdventureWorks’)

EXEC(@SQL)

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close