Again, if you want to delete all user databases with a single TSQL script, you can achieve this easily by using this script

DECLARE @command nvarchar(max)

SET @command = ''

SELECT  @command = @command

+ 'ALTER DATABASE [' + [name] + ']  SET single_user with rollback immediate;'+CHAR(13)+CHAR(10)

+ 'DROP DATABASE [' + [name] +'];'+CHAR(13)+CHAR(10)

FROM  [master].[sys].[databases] 

 where [name] not in ( 'master', 'model', 'msdb', 'tempdb');

SELECT @command

EXECUTE sp_executesql @command

Please ensure to backup all you databases before (how to back up everything)

Use this script at your own risk

Show Buttons
Hide Buttons

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.