USE master
GO

DECLARE @DBNAME VARCHAR(50)

SET @DBNAME = ‘HD’

DECLARE @HoldSql VARCHAR(500)

EXEC msdb.dbo.sp_delete_database_backuphistory @database_name = @DBNAME

SET @HoldSql = ‘ALTER DATABASE [‘ + @DBNAME + ‘] SET SINGLE_USER WITH ROLLBACK IMMEDIATE’

EXECUTE (@HoldSql)

SET @HoldSql = ‘DROP DATABASE [‘ + @DBNAME + ‘]’

EXECUTE (@HoldSql)

if you need to know How to Drop all Databases in your Server Check this link

Drop All Databases in SQL Server

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.