SQL SERVER Lookup Lock Information

Source: Internet
Author: User

Through the system's stored procedure sp_who or Sp_who2 can find all the lock information, but do not see which table, what statement

When using sp_who or Sp_who2 to find the lock information, there is a SPID information, you can use the following statement to find out the corresponding statement

DBCC InputBuffer (SPID)

Use this statement, not necessarily can find information, can find out, is the execution of the statement, also said this is to check the deadlock statement.

The following statement checks the number of deadlocks

Select Blockedfrom (SELECT * from sys.sysprocesses where  blocked>0) a where isn't exists (SELECT * FROM (SELECT * Fro M sys.sysprocesses where  blocked>0) b where a.blocked=spid)

 

Use the following statement to find out which tables are locked and how many times they are locked

Select TableName, COUNT (*) CNT from (select   request_session_id   spid,object_name (resource_associated_entity_ ID) tableName   from   sys.dm_tran_locks where resource_type= ' OBJECT ') AA group by Tablenameorder by CNT Desc

SQL SERVER Lookup Lock Information

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.