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!