Query over results of 'sp_lock' in SQL Server

tyg4sfes  于 8个月前  发布在  SQL Server
关注(0)|答案(1)|浏览(76)

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 ?

bqucvtff

bqucvtff1#

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:

select *
from sys.dm_tran_locks
where resource_database_id = db_id()

相关问题