Tuesday, March 3, 2015

When a team member is being a resource hog...

(no real content in this post, just me having fun with a team)

Teach them a lesson by killing all of their sessions...

--drop table #temp
create table #temp (spid int, ecid int, status varchar(255),loginname varchar(255), hostname varchar(255), blk int, dbname varchar(255), cmd varchar(255), request_id int)

insert into #temp
execute sp_who

declare @spid int
declare @sql varchar(max)

DECLARE state_scroll CURSOR FOR
select spid
from #temp
where loginname like '%levi%'


OPEN state_scroll

FETCH NEXT FROM state_scroll
INTO @spid

WHILE @@FETCH_STATUS = 0
BEGIN


set @sql = 'kill ' + cast(@spid as varchar(255))
execute(@sql)

FETCH NEXT FROM state_scroll
INTO @spid
END

CLOSE state_scroll
DEALLOCATE state_scroll

No comments:

Post a Comment