Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"Drop Database" + Close Existing Connections 1

Status
Not open for further replies.

webuser

MIS
Jun 1, 2001
202
0
0
US
In Management Studio, when you delete a DB, there is a check box that optionally allows you to drop all existing connections. Is there an equivalent in T-SQL? So far, I have found that the "Drop Database" command has no parameters that can be used for this. And if not, how can I, using T-SQL, drop all connections to a DB?

Thanks in advance!!!
 
you can use sp_who2, which lists all connections onto a database, and then you can run KILL (spid), replacing (spid) with the process id you have captured from sp_who2.
This will kill the process and connection.

"I'm living so far beyond my income that we may almost be said to be living apart
 
Thanks. How would this be done in an automated way, like if the script had to run as part of a build?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top