CREATE PROCEDURE dbo.KillConexiones
@dbName SYSNAME
AS
BEGIN
SET NOCOUNT ON
DECLARE @spid INT,
@cnt INT,
@sql VARCHAR(255)
SELECT @spid = MIN(spid), @cnt = COUNT(*)
FROM master..sysprocesses
WHERE dbid = DB_ID(@dbname)
AND spid != @@SPID
PRINT 'Eliminando '+RTRIM(@cnt)+' procesos.'
WHILE @spid IS NOT NULL
BEGIN
PRINT 'Eliminando Proceso '+RTRIM(@spid)
SET @sql = 'KILL '+RTRIM(@spid)
EXEC(@sql)
SELECT @spid = MIN(spid), @cnt = COUNT(*)
FROM master..sysprocesses
WHERE dbid = DB_ID(@dbname)
AND spid != @@SPID
PRINT RTRIM(@cnt)+' Procesos por eliminar.'
END
END
GO
No hay comentarios:
Publicar un comentario