Delete all User databases with TSQL
![](https://i0.wp.com/samtech365.com/wp-content/uploads/2018/03/n1610091.jpg?fit=512%2C512&ssl=1)
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