Created
September 2, 2016 14:42
-
-
Save arman-hpp/62dbe10f4c8183528c1dd225c51be95b to your computer and use it in GitHub Desktop.
Drop All Databases
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 nvarchar(255) | |
DECLARE db CURSOR FOR | |
SELECT Name FROM sysdatabases | |
WHERE Name NOT IN ('master', 'tempdb', 'model', 'msdb') | |
OPEN db; | |
FETCH NEXT FROM db | |
INTO @name; | |
WHILE @@FETCH_STATUS = 0 | |
BEGIN | |
PRINT 'DROP DATABASE [' + REPLACE( @name, ']', ']]' ) + ']' | |
PRINT 'GO' | |
FETCH NEXT FROM db | |
INTO @name | |
END | |
CLOSE db; | |
DEALLOCATE db; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment