TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
How to Kill all the Blocked Processes of a Database
Ashish Srivastava
May 18
2016
Code
718
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
DECLARE
@DatabaseName nvarchar(50)
--Set the Database Name
SET
@DatabaseName = N
'TESTDB'
--Select the current Daatbase
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
spid
IN
(
SELECT
blocked
FROM
master.dbo.sysprocesses)
exec
@SQL
SQL Server
Blocked Processes
Database