Cannot delete database in SQL Server 2012

I created a sample database before, and now I want to delete this database, but it is not deleted. I searched on the Internet, but I did not find any solution that works.

Using T-SQL, I tried:

USE [Sample]

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

DROP DATABASE [Sample]

Using the GUI, I get the following:

enter image description here

I closed the existing connection and this happens and this is my local machine. Please help me here!

+1
source share
5 answers

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
+1
source

Close SSMS, open a new instance and try the following: copy all this into a new query window and do it right away:

USE [master];            
GO

ALTER DATABASE [Sample]   --<-- go back into Multi-user mode
SET MULTI_USER;
GO

ALTER DATABASE [Sample]   --<-- Will disconnect everyone 1st
SET SINGLE_USER              -- and will leave the database in single user mode
WITH ROLLBACK IMMEDIATE;
GO

USE [Sample];                -- quickly grab that single connection before any 
GO                           -- other process does

USE [master];                -- Connect to master db,  connection
GO                           -- This also means disconnect Sample DB 

DROP DATABASE [Sample]       -- At this point there should be no active connections
GO                           -- to this database and can be dropped 
0
source

( )

  • Microsoft SQL Server Management Studio , ( , ), .
  • .
  • " .
  • MULTI_USER SINGLE_USER
  • ( )

Screenshot

0

, ,

5011, 14, 7, 2 "CMS_Import_SA", , . 5069, 16, 1, 2: ALTER DATABASE . 5011, 14, 7, 2 "DB_name", , . 5069, 16, 1, 2: ALTER DATABASE . 922, 14, 1, 2 . . 922, 14, 1, 2 . . 3702, 16, 4, 2 "" , .

0
source

Using this code should help.

ALTER DATABASE [database_name] SET SINGLE_USER --or RESTRICTED_USER with the ROLLBACK option; GO DROP DATABASE [database name]; GO

0
source

All Articles