SQL Server table deadlock resolution sharing _mssql

Source: Internet
Author: User
In fact, not only the situation described above will lock the table, there are many kinds of scenes that will put the table to lock the life and death, unlock is actually very simple, the following an example to explain:

1 Create a test table first:
Copy Code code as follows:

CREATE TABLE Test
(
TID INT IDENTITY (1,1)
)

2 Execute the following SQL statement to lock the table:
Copy 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 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 results of the above statement are as follows:


SPID: the lock process ID.
TableName: The name of the table in which the deadlock occurred.

5 You can unlock a table simply by using the KILL keyword to kill the locked process ID:

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.