Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to query locked sql by sqlserver

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the sqlserver query locking sql and unlocking methods, the article is very detailed, has a certain reference value, interested friends must read it!

-- View the locked table:

SELECT request_session_id spid, OBJECT_NAME (resource_associated_entity_id) tableNameFROM sys.dm_tran_locksWHERE resource_type = 'OBJECT' ORDER BY request_session_id ASC--spid locking table process-- tableName locked table name

-- query the SQL statement of the corresponding process interlock according to the locking table process

DBCC INPUTBUFFER (249)

-- unlock:

DECLARE @ spid INT SET @ spid = 52 Muir-Table Lock process DECLARE @ SQL VARCHAR (1000) SET @ SQL = 'kill' + CAST (@ spid AS VARCHAR) EXEC (@ SQL)

-- generate an unlocked SQL

SELECT DISTINCT 'DECLARE @ spid INT SET @ spid =', request_session_id,' DECLARE @ SQL VARCHAR (1000) SET @ SQL =''kill''+ CAST (@ spid AS VARCHAR) EXEC (@ SQL);'as sFROM sys.dm_tran_locksWHERE resource_type = 'OBJECT'-- spid Table Lock process-- tableName locked Table name above is all the contents of the article "sqlserver query locking sql and unlocking methods". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report