Script to kill all connections to a database (More than RESTRICTED_USER ROLLBACK)

后端 未结 14 1568
-上瘾入骨i
-上瘾入骨i 2020-11-28 17:28

I have a development database that re-deploy frequently from a Visual Studio Database project (via a TFS Auto Build).

Sometimes when I run my build I get this error:

14条回答
  •  甜味超标
    2020-11-28 18:02

    You can get the script that SSMS provides by doing the following:

    1. Right-click on a database in SSMS and choose delete
    2. In the dialog, check the checkbox for "Close existing connections."
    3. Click the Script button at the top of the dialog.

    The script will look something like this:

    USE [master]
    GO
    ALTER DATABASE [YourDatabaseName] SET  SINGLE_USER WITH ROLLBACK IMMEDIATE
    GO
    USE [master]
    GO
    DROP DATABASE [YourDatabaseName]
    GO
    

提交回复
热议问题