Theres is a built-in stored procedure in SQL Server called sp_lock.
It will return a table which contains information about current locks in database server. It will return several columns including dbid
which is id of each database. I want to query only one specific database id, but I don't know how to execute a query over returned result of sp_lock
.
I want to know how to query over results of sp_lock
?
See the "Important" note in the documentation you link, you should be querying sys.dm_tran_locks not using this deprecated proc (Which sp_helptext 'sp_lock' indicates dates back to 1996), eg this will return locks in the current database: