[SQL] Disconnects all active connections of a database with an SQL statement

Source: Internet
Author: User

1 Use Master2 Go3 4IF EXISTS (SELECT *5 From dbo.sysobjects6WHERE id = object_id (N'[dbo]. [P_killconnections]')7and OBJECTPROPERTY (ID, N'isprocedure') =1 ) 8 DROP PROCEDURE [dbo]. [P_killconnections]9 GOTen  OneCREATE PROC p_killconnections @dbname VARCHAR ( $) A  as -DECLARE @sql NVARCHAR ( -) -DECLARE @spid NVARCHAR ( -) the  - DECLARE #tb CURSOR for -SELECT spid=cast (spid as VARCHAR ( -) from Master. sysprocesses WHERE dbid=db_id (@dbname) - OPEN #tb + FETCH NEXT from #tb into @spid -While @ @fetch_status =0  + BEGIN AEXEC ('Kill'+@spid) at FETCH NEXT from #tb into @spid - END - CLOSE #tb - deallocate #tb - Go -  in  ---Modify toEXEC p_killconnections'change to your own database'

[SQL] Disconnects all active connections to a database with an SQL statement

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.