我之前已经创建了一个示例数据库,现在我想要删除该数据库,但它没有被删除。我在网上搜索,但我找不到任何有效的解决方案。
使用T-SQL,我试过:
USE [Sample]
ALTER DATABASE [Sample]
SET SINGLE_USER
WITH ROLLBACK IMMEDIATE;
GO
DROP DATABASE [Sample]
使用GUI,我收到以下错误:
我关闭了现有连接,然后这也发生了,这是我的本地机器。请帮帮我!
答案 0 :(得分:1)
使用此代码:
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 :(得分:0)
关闭您的SSMS,打开一个新实例,然后尝试以下操作,复制将整个内容粘贴到一个新的查询窗口并立即执行:
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
答案 2 :(得分:0)
删除数据库的另一种方法(无编码)
答案 3 :(得分:0)
使用此代码应有帮助。
ALTER DATABASE [dbname]
SET SINGLE_USER --or RESTRICTED_USER
WITH ROLLBACK IMMEDIATE;
GO
DROP DATABASE [dbname];
GO