SQL Server: Killing Sessions through T-SQL
DECLARE @DatabaseName nvarchar(50)
SET @DatabaseName = N'Works'
--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
-- SELECT @SQL
EXEC(@SQL)
Source:
http://www.kodyaz.com/articles/kill-all-processes-of-a-database.aspx
SET @DatabaseName = N'Works'
--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
-- SELECT @SQL
EXEC(@SQL)
Source:
http://www.kodyaz.com/articles/kill-all-processes-of-a-database.aspx
Comments
Post a Comment