Close Database Connections From T-SQL

In my recent project, I was required to drop a database while there where probably some open connections.

I googled it and came across this.

So the following is the command I use.

ALTER DATABASE DATABASE_NAME SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
DROP DATABASE DATABASE_NAME
GO

3 Responses to “Close Database Connections From T-SQL”

  1. Adam Says:

    Lovely…thanks!

  2. jbrechtel Says:

    Sweet, thanks

  3. CSutcliffe Says:

    Very nice… Thank you so much.

Leave a Reply