Workaround for SQL Server table deadlock

Source: Internet
Author: User

1 first create a test table:

Copy the code code as follows:

CREATE TABLE Test (TID INT IDENTITY)

2 Execute the following SQL statement to lock the table:

Copy the code code as follows:

SELECT * from Test with (Tablockx)

3 You can see which tables in the current library are deadlocked by using the following statement:

Copy the code code as follows:

SELECT request_session_id spid,object_name (resource_associated_entity_id) tableName from Sys.dm_tran_locks WHERE Resource_type= ' OBJECT '

4 The result of the above statement execution is as follows:

  

SPID: The process ID being locked. TableName: The name of the table where the deadlock occurred.
5 only use the KILL keyword to kill the locked process ID to unlock the table:
KILL 52

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.