Skip to content

Instantly share code, notes, and snippets.

@arman-hpp
Created September 2, 2016 14:42
Show Gist options
  • Save arman-hpp/62dbe10f4c8183528c1dd225c51be95b to your computer and use it in GitHub Desktop.
Save arman-hpp/62dbe10f4c8183528c1dd225c51be95b to your computer and use it in GitHub Desktop.
Drop All Databases
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