开发者

Enforce SQL Server to drop a database

开发者 https://www.devze.com 2023-01-05 00:53 出处:网络
When I\'m using Management Studio Express to drop a database there is an checkbox \"Close existing connections.\" which close open database a开发者_JAVA百科nd enforce it to drop.

When I'm using Management Studio Express to drop a database there is an checkbox "Close existing connections." which close open database a开发者_JAVA百科nd enforce it to drop.

How can i drop a database programmatic by closing open connections and check it's ever exists before?


The output of the "script" icon on the drop screen, as suggested in the comments by Randolph Potter (this assumes that your database name is "test"):

EXEC msdb.dbo.sp_delete_database_backuphistory @database_name = N'test'
GO
USE [master]
GO
ALTER DATABASE [test] SET  SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
USE [master]
GO
/****** Object:  Database [test]    Script Date: 06/30/2010 09:12:29 ******/
DROP DATABASE [test]
GO
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号