Sqlserver: Query lock SQL statements and Unlock methods. sqlserversql

Source: Internet
Author: User

Sqlserver: Query lock SQL statements and Unlock methods. sqlserversql

View locked table statements

-- View the locked table: SELECTrequest_session_id spid, OBJECT_NAME (resource_associated_entity_id) tableNameFROMsys. dm_tran_locksWHEREresource_type = 'object' order by request_session_id ASC -- spid lock table process -- tableName lock table name -- query the SQL statement DBCC INPUTBUFFER (249) of mutual lock of the corresponding process based on the lock table process)

Unlock statement

-- Unlock: DECLARE @ spid INTSET @ spid = 52 -- lock table process DECLARE @ SQL varchar (1000) SET @ SQL = 'Kill '+ CAST (@ spid AS VARCHAR) EXEC (@ SQL)

Generate an unlock SQL statement

-- Generate and unlock SQLSELECTDISTINCT 'DECLARE @ spid int set @ spid =', request_session_id, 'destare @ SQL VARCHAR (1000) SET @ SQL = ''kill ''+ CAST (@ spid as varchar) EXEC (@ SQL); 'as sFROMsys. dm_tran_locksWHEREresource_type = 'object' -- spid lock table process -- tableName locked table name

Summary

The above is all about sqlserver: querying and locking SQL statements and unlocking methods. I hope it will be helpful to you. For more information, see MYSQL subquery and nested query optimization instance resolution, several important MySQL variables, and analysis of technical points of oracle SQL statement optimization, you can leave a message at any time. The editor will reply to you in a timely manner and strive to provide better articles and better reading experience for the majority of programming hobbies and workers. Thank you for your support!

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.