sql-servert-sqldrop-table

Unable to drop database in SQL Server 2012


I have created a sample database earlier and now I want to delete that database, but it is not getting deleted. I searched online but I didn't find any solution which is working.

Using T-SQL, I tried:

USE [Sample]

ALTER DATABASE [Sample]
SET SINGLE_USER
WITH ROLLBACK IMMEDIATE;
GO

DROP DATABASE [Sample]

Using the GUI, I am getting this below error:

enter image description here

I closed existing connection then also this is happening and this is my local machine. Please help me here!


Solution

  • use this code:

    USE MASTER 
    GO
    
    ALTER DATABASE Sample 
    SET multi_user WITH ROLLBACK IMMEDIATE
    GO
    
    
    ALTER DATABASE Sample
    SET SINGLE_USER WITH ROLLBACK IMMEDIATE
    GO
    
    DROP DATABASE Sample
    GO