How to tell if current session is holding a lock?

Viewed 68

Is there a query I can run in SSMS to see if the current session I am in has a lock. Like if a BEGIN TRAN statement was run and never resolved, is there a query that would show that? And again, specifically whether the tab/session I'm currently typing in is the one with the lock?

1 Answers

Sure, the DMV sys.dm_tran_locks shows all currently held or requested locks and the function @@spid returns the current session_id,

So:

select *
from sys.dm_tran_locks
where request_session_id = @@spid
Related