Created
October 19, 2021 10:26
-
-
Save Toumash/bac1a16e1ed4c7c2f7a945863525cb30 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
DECLARE @name VARCHAR(100) -- database name | |
DECLARE @SQLString nvarchar(200) | |
DECLARE db_cursor CURSOR FOR | |
SELECT name | |
FROM MASTER.dbo.sysdatabases | |
WHERE name NOT IN ('master','model','msdb','tempdb','spare-me','me-too') | |
OPEN db_cursor | |
FETCH NEXT FROM db_cursor INTO @name | |
use master | |
WHILE @@FETCH_STATUS = 0 | |
BEGIN | |
SET @SQLString = 'ALTER DATABASE [' + @name +'] SET single_user with ROLLBACK IMMEDIATE; | |
DROP DATABASE [' + @name +']'; | |
EXECUTE (@SQLString) | |
FETCH NEXT FROM db_cursor INTO @name | |
END | |
CLOSE db_cursor | |
DEALLOCATE db_cursor |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment