SQL Server process deadlock closure method, SQL Server process

Source: Internet
Author: User

SQL Server process deadlock closure method, SQL Server process

1. First, we need to determine which user has locked the table.

-- Query the lock table select request_session_id spid, OBJECT_NAME (resource_associated_entity_id) tableName from sys. dm_tran_locks where resource_type = 'object'

After the query, a table containing the spid and tableName columns is returned.

Spid is the process name and tableName is the table name.

2. Find out which table is locked by the process and find the host of the table.

-- Query the process where the host name exec sp_who2 'xxx' xxx is the spid column. A lot of information is listed after the query, including the host name.

3. Close the process by using the value of the spid column.

-- Disable the process declare @ spid int Set @ spid = xxx -- lock the table process declare @ SQL varchar (1000) set @ SQL = 'Kill '+ cast (@ spid as varchar) exec (@ SQL)

PS: in some cases, it is dangerous to forcibly kill a process, so it is best to find the host that executes the process and shut down the process on this machine.

The above is a small Editor to introduce you to the sqlserver process deadlock closure method, I hope to help you, if you have any questions, please leave a message, the small editor will reply to you in a timely manner. Thank you very much for your support for the help House website!

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.