清除所有连接会话--------存储过程

--存储过程 清除所有连接会话
CREATE PROCEDURE 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
 

你可能感兴趣的:(sql)