您的位置:首页 > 数据库

sql server 强制删除连接

2012-09-12 15:39 190 查看
用SQl语句控制MS SQl server的用户连接

if exists(select 1 from sysobjects where name = 'killspid' and type = 'P')

drop proc killspid

create proc killspid (@dbname varchar(20))

as

begin

declare @sql nvarchar(500)

declare @spid int

set @sql='declare getspid cursor for

select spid from sysprocesses where dbid=db_id('''+@dbname+''')'

exec (@sql)

open getspid

fetch next from getspid into @spid

while @@fetch_status < >-1

begin

exec('kill '+@spid)

fetch next from getspid into @spid

end

close getspid

deallocate getspid

end

--用法

use master

exec killspid '数据库名'
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: