r/MSSQL • u/sharpbranches • Mar 10 '22
Best Practice Creating a stored procedure that kill blocking process?
I found one on the Internet, but I am not sure how good it is. I also would like to know how to give permission to a user to only run the stored procedure. Do I need to give that user write access only to the master db where you can run the stored procedure to kill blocking processes? Because in my understanding the processes are held in the master table.
0
Upvotes
2
u/alinroc Mar 11 '22
No one here can comment on the quality of what you found if you don't point us at it.
Your understanding is incorrect. There is no "master table" and processes are not "held" in a table like you're thinking.
Here are the permissions required to kill a session/process. You can muck around with
EXECUTE ASand other techniques but just letting a random user do this is potentially dangerous.Before you start haphazardly killing blocking processes, seek to understand why these conditions are arising and take actions to prevent them from happening in the first place. Just killing any process "because it's causing blocking" may make the situation worse - or perhaps even worse than that, could leave your data in a bad state.