zoukankan      html  css  js  c++  java
  • sqlserver:查询锁住sql以及解锁

    --查看被锁表:
    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 被锁表名

    --根据锁表进程查询相应进程互锁的SQL语句
    DBCC INPUTBUFFER (249)

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

    --生成解锁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 被锁表名

    各位看官大佬,不足之处,多多批评指正,不胜感激!
  • 相关阅读:
    Leetcode 83. Remove Duplicates from Sorted List
    Leetcode 61. Rotate List
    Leetcode 24. Swap Nodes in Pairs
    增强式学习
    散布矩阵
    特征选择
    CouchDB
    echarts和matplotlib
    特征缩放
    K-means、SLC、EM
  • 原文地址:https://www.cnblogs.com/guoguochong/p/7651549.html
Copyright © 2011-2022 走看看