Drop Database in Azure Data Studio

Dropping a database from an instance of Azure Data Studio Server and it deletes the physical disk files used by the database

Syntax: -
-- Drop the database 'DatabaseName'
-- Connect to the 'master' database to run this snippet
USE master
GO
-- Uncomment the ALTER DATABASE statement below to set the database to SINGLE_USER mode if the drop database command fails because the database is in use.
-- ALTER DATABASE DatabaseName SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
-- Drop the database if it exists
IF EXISTS (
  SELECT [name]
   FROM sys.databases
   WHERE [name] = N'DatabaseName'
)
DROP DATABASE DatabaseName
GO
Example : -
USE master
GO
IF EXISTS (
  SELECT [name]
   FROM sys.databases
   WHERE [name] = N'TestDB'
)
DROP DATABASE TestDB
GO

*****************
Or
DROP DATABASE TestDB
GO
-- TestDB is Database Name.

Happy Coding… Thanks.

Post Author: adama