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