Search

Tuesday, May 15, 2012

Killed Last 10 min Inactive Sessions of a Database

DECLARE @DatabaseName nvarchar(50)

SET @DatabaseName = N'DATABASE NAME'

--SET @DatabaseName = DB_NAME()

DECLARE @SQL varchar(max)

SET @SQL = ''

SELECT @SQL = @SQL + 'Kill ' + Convert(varchar, SPId) + ';'

FROM MASTER..SysProcesses

WHERE DBId = DB_ID(@DatabaseName) AND SPId <> @@SPId

AND DATEDIFF(mi,last_batch,GETDATE())>=10

-- SELECT @SQL

EXEC(@SQL)

No comments:

Post a Comment