/ Published in: SQL
If you have ever tried to restore a database and could not obtain exclusive access, you know how useful this can be.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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
URL: http://www.mssqltips.com/sqlservertip/1521/the-many-uses-of-coalesce-in-sql-server/