세션 연결 끊는 쿼리

USE [master]
GO

DECLARE @spidstr VARCHAR(8000) = null
SELECT @spidstr=coalesce(@spidstr,' ' )+'kill '+convert(varchar, exec_session_.session_id)+ '; '
from master.sys.dm_exec_sessions exec_session_
join (
select spid from master.dbo.sysprocesses ps1_
where ps1_.dbid = (
select db_.dbid from master.dbo.sysdatabases db_
join master.dbo.sysprocesses ps2_ on ps2_.dbid = db_.dbid and ps2_.spid = @@SPID )
) session1_ on exec_session_.session_id = session1_.spid
where exec_session_.login_name = N'sa'
EXEC(@spidstr)
GO


--해당 계정 연결 끊기
USE [master]
GO

DECLARE @spidstr VARCHAR(8000) = null
SELECT @spidstr=coalesce(@spidstr,' ' )+'kill '+convert(varchar, exec_session_.spid)+ '; '
from master.dbo.sysprocesses as exec_session_ where loginame = N'webadmin'
EXEC(@spidstr)
GO

댓글 없음: