Created
August 6, 2021 12:55
-
-
Save stevewithington/7a0f86b26c78d6a019534863c65f4772 to your computer and use it in GitHub Desktop.
Kill all transactions in a database during a restore to avoid issues with exclusive access.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Kill all transactions in a database during a restore to avoid issues with exclusive access. | |
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 | |
-- https://www.mssqltips.com/sqlservertip/1521/the-many-uses-of-coalesce-in-sql-server/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment