Kill Session in Microsoft SQL Server.
DECLARE @ID INT
DECLARE @MSG CHAR(8)
While 1 = 1
BEGIN
Set RowCount 1
SELECT
@id =
spid
FROM
Master..Sysprocesses P,
Master..Sysdatabases D
WHERE
D.Name='DatabaseName'
AND
D.dbid = P.dbid
--and P.blocked<>0 --if you want to kill blocked session.
IF @@rowcount = 0
break
SELECT @msg = 'KILL ' + convert(char(8) ,@ID)
Print @msg
EXEC( @msg)
--break
END
GO
DECLARE @MSG CHAR(8)
While 1 = 1
BEGIN
Set RowCount 1
SELECT
@id =
spid
FROM
Master..Sysprocesses P,
Master..Sysdatabases D
WHERE
D.Name='DatabaseName'
AND
D.dbid = P.dbid
--and P.blocked<>0 --if you want to kill blocked session.
IF @@rowcount = 0
break
SELECT @msg = 'KILL ' + convert(char(8) ,@ID)
Print @msg
EXEC( @msg)
--break
END
GO
Comments
Post a Comment
Dear User,
Thank you very much for your kind response