当前位置:网站首页>Table lock query and unlocking in SQL development part 1
Table lock query and unlocking in SQL development part 1
2022-07-28 15:21:00 【A grain of sand in the sea】
1、 Query table lock process id
select request_session_id spid,OBJECT_NAME(resource_associated_entity_id) tableName
from sys.dm_tran_locks where resource_type='OBJECT'
2、 According to the process id kill fall
spid To query the process number
declare @spid int
Set @spid = 56
declare @sql varchar(1000)
set @sql='kill '+cast(@spid as varchar)
exec(@sql)
3、 Cursor loop releases table lock
DECLARE @spid VARCHAR(50),
@talbename varchar(100)
DECLARE cursor_name CURSOR FOR -- Define cursors
SELECT request_session_id spid,OBJECT_NAME(resource_associated_entity_id) tableName
from sys.dm_tran_locks where resource_type='OBJECT'
OPEN cursor_name -- Open cursor
FETCH NEXT FROM cursor_name INTO @spid,@talbename -- Grab the next row of cursor data
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT ' Table name :'+@talbename+' '+'spid:'+@spid
exec('kill '+@spid)
FETCH NEXT FROM cursor_name INTO @spid,@talbename
END
CLOSE cursor_name -- Close cursor
DEALLOCATE cursor_name -- Release cursor
边栏推荐
- R introduction example details
- [touch] count the number of engineering documents, code lines, and line comment coverage
- Requses template
- MPLS LDP的原理与配置
- [Game Testing Engineer] get to know game testing for the first time - do you know it?
- The automatic prompt of vs code code is missing - a tick to solve it
- crmeb知识付费手动安装教程
- Three pain points of software development! How to solve the applet container?
- .net core 2.2 版本跨域配置
- day 7/12
猜你喜欢
随机推荐
4519. Number of square arrays
3438. 数制转换
Mysql易错知识点整理(待更新)
【LeetCode】35、搜索插入位置
List of security technologies to be considered in cloud computing
一文看懂CRMEB开源在线教育知知识付费系统
为什么企业需要用户自治的数字身 份
pyppeteer 遇到的问题
The first self introduction quotation
4518. 最低票价
3438. Number system conversion
手摸手实现Canal如何接入MySQL实现数据写操作监听
RY-D1/1电压继电器
The automatic prompt of vs code code is missing - a tick to solve it
Publish raspberry pie web page with cpolar (apache2 installation test)
What functions will be added to crmeb Standard Version 4.4
每日一题(回溯)
3564. 日期类
2021 year end summary of gains and losses
新版数据同步问题









