Home > Database > Mysql Tutorial > body text

How to query locked sql and unlock using sqlserver

一个新手
Release: 2017-10-18 10:23:28
Original
1654 people have browsed it

--View the locked table:

SELECT
    request_session_id spid,
    OBJECT_NAME(
        resource_associated_entity_id
    ) tableName
FROM
    sys.dm_tran_locks
WHERE
    resource_type = 'OBJECT' 
ORDER BY request_session_id ASC
--spid   锁表进程 
    --tableName   被锁表名
Copy after login

--Query the SQL statement of the corresponding process interlock according to the lock table process
DBCC INPUTBUFFER (249)

-- Unlock:

 DECLARE
        @spid INT
    SET @spid = 52--锁表进程
    DECLARE
        @SQL VARCHAR (1000)
    SET @SQL = 'kill ' + CAST (@spid AS VARCHAR) EXEC (@SQL)
Copy after login

-- Generate unlocking 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 s
FROM
    sys.dm_tran_locks
WHERE
    resource_type = 'OBJECT'   --spid   锁表进程 
    --tableName   被锁表名
Copy after login

The above is the detailed content of How to query locked sql and unlock using sqlserver. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!