Return to Snippet

Revision: 60068
at October 19, 2012 03:34 by derebus


Initial Code
DECLARE @SQL VARCHAR(8000) 

SELECT @SQL=COALESCE(@SQL,'')+'Kill '+CAST(spid AS VARCHAR(10))+ '; '  
FROM sys.sysprocesses  
WHERE DBID=DB_ID('AdventureWorks') 

PRINT @SQL --EXEC(@SQL) Replace the print statement with exec to execute

Initial URL
http://www.mssqltips.com/sqlservertip/1521/the-many-uses-of-coalesce-in-sql-server/

Initial Description
If you have ever tried to restore a database and could not obtain exclusive access, you know how useful this can be.

Initial Title
kill all the transactions in a database

Initial Tags

                                

Initial Language
SQL