segunda-feira, 20 de agosto de 2018

Need a fast way to kill all connetions to a Database on SQL SERVER?

Need a fast way to kill all connetions to a Database on SQL SERVER? Try this:

USE [master];

DECLARE @kill varchar(8000) = '';  
SELECT @kill = @kill + 'kill ' + CONVERT(varchar(5), session_id) + ';'  
FROM sys.dm_exec_sessions
WHERE database_id  = db_id('YourDatabase')

EXEC(@kill);


Just replace "YourDatabase" with the database that you need to work on and that is it!



--
Check out my new book about R Language http://www.amazon.com/dp/B00SX6WA06

Nenhum comentário:

Postar um comentário

Leave your comment here!