SQL Server lock mechanism

Source: Internet
Author: User

How to view Locks

Understanding the locking of SQL Server at a certain point in time is undoubtedly an effective means of learning to lock and diagnose database deadlock and performance. The most common way to view database locks is in two ways:

Use sys.dm_tran_locks this DMV

SQL Server provides sys.dm_tran_locks this DMV to view the locks in the current database, as shown in the previous Figure 2 by this DMV.

It is worth noting that sys.dm_tran_locks this DMV sees a database lock at a point in time, and does not contain any history lock records. Can be understood as a snapshot of how the database locks up at the point of query time. The information contained in Sys.dm_tran_locks is divided into two categories, the information describing the resource in which the lock is located at the beginning of the resource, and another class of information that describes the requested lock itself, starting with request.

Select
STR (request_session_id,4,0) as SPID,
CONVERT (varchar), db_name (resource_database_id)) as Db_name,
case when resource_data_id = db_id () and resource_type= ' OBJECT '
Then convert (char (), object_name (resource_associated_entity_id))
else convert (char (), resource_associated_entity_id)
End As Object,
CONVERT (varchar (), resource_type) as Resrc_type,
CONVERT (varchar (), request_type) as Req_type,
Convert (char (3), Request_mode) as mode,
CONVERT (varchar (8), request_status) as Status
From sys.dm_tran_locks
ORDER BY request_session_id Desc

SQL Server lock mechanism

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.