惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

罗磊的独立博客
SecWiki News
SecWiki News
酷 壳 – CoolShell
酷 壳 – CoolShell
爱范儿
爱范儿
量子位
M
MIT News - Artificial intelligence
GbyAI
GbyAI
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
TaoSecurity Blog
TaoSecurity Blog
博客园 - 【当耐特】
H
Heimdal Security Blog
腾讯CDC
The Last Watchdog
The Last Watchdog
Security Archives - TechRepublic
Security Archives - TechRepublic
Hacker News: Ask HN
Hacker News: Ask HN
S
Schneier on Security
Microsoft Security Blog
Microsoft Security Blog
WordPress大学
WordPress大学
博客园 - 司徒正美
Recent Commits to openclaw:main
Recent Commits to openclaw:main
C
Cybersecurity and Infrastructure Security Agency CISA
S
SegmentFault 最新的问题
大猫的无限游戏
大猫的无限游戏
Application and Cybersecurity Blog
Application and Cybersecurity Blog
F
Full Disclosure
有赞技术团队
有赞技术团队
T
Tailwind CSS Blog
Engineering at Meta
Engineering at Meta
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
T
Threatpost
月光博客
月光博客
A
Arctic Wolf
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
雷峰网
雷峰网
T
Troy Hunt's Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
The Cloudflare Blog
D
DataBreaches.Net
O
OpenAI News
L
LINUX DO - 最新话题
宝玉的分享
宝玉的分享
小众软件
小众软件
V
Vulnerabilities – Threatpost
A
About on SuperTechFans
人人都是产品经理
人人都是产品经理
T
The Exploit Database - CXSecurity.com
Martin Fowler
Martin Fowler
美团技术团队
P
Privacy International News Feed

博客园 - 在北京的湖南人

Table变量和临时表区别 C#trim不掉空格的原因 - 在北京的湖南人 - 博客园 vss2005 只获取到文件夹获取不到文件的解决 关于asp.net session机制的疑惑以及猜想 一段关于浏览器兼容的事件定位代码,经过测试! 收集关于scrollTop信息 数据库中null字段在逻辑层的判断的两种办法 - 在北京的湖南人 - 博客园 sql server 2005 新分页存储过程 sql 优化之关于null 和数据类型 js trim函数 复制粘贴都出错,还有什么错不能出的? sql 优化实战 从 35秒到0秒 又从0秒到25秒 asp.net上传时出现的问题:"对路径的访问被拒绝" gridview超链接列带多个参数 访问 IIS 元数据库失败 sql server clr 集成系列之四 创建一个clr的表值函数---实用的Split函数 sql server 2005 clr 集成 之三 关于context connetion sql server clr 集成系列之二 简单的sql 函数 Sql server 2005 Clr集成系列开篇 为什么微软要集成clr 到sql server?
return语句写错地方导致数据库表长时间被锁
在北京的湖南人 · 2007-03-13 · via 博客园 - 在北京的湖南人

项目中一位朋友在使用事务的时候return写错地方了,事务还没有结束,sp就已经结束了,然后我们用select *  都出不来数据,只有用select * form table1 with(nolock)  才能够出来。不过我还在网上找到了一个好的重写sp_who_lock 的存储过程,拿出来大家一起共享。

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sp_who_lock]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[sp_who_lock]
GO


use master
go
create procedure sp_who_lock
as
begin
declare @spid int,@bl int,
@intTransactionCountOnEntry int,
        @intRowcount int,
        @intCountProperties int,
        @intCounter int

create table #tmp_lock_who (
id int identity(1,1),
spid smallint,
bl smallint)

IF @@ERROR<>0 RETURN @@ERROR

insert into #tmp_lock_who(spid,bl) select  0 ,blocked
  from (select * from sysprocesses where  blocked>0 ) a
  where not exists(select * from (select * from sysprocesses where  blocked>0 ) b
  where a.blocked=spid)
  union select spid,blocked from sysprocesses where  blocked>0

IF @@ERROR<>0 RETURN @@ERROR
 
-- 找到临时表的记录数
select @intCountProperties = Count(*),@intCounter = 1
from #tmp_lock_who

IF @@ERROR<>0 RETURN @@ERROR

if @intCountProperties=0
select '现在没有阻塞和死锁信息' as message

-- 循环开始
while @intCounter <= @intCountProperties
begin
-- 取第一条记录
select @spid = spid,@bl = bl
from #tmp_lock_who where Id = @intCounter
begin
 if @spid =0
            select '引起数据库死锁的是: '+ CAST(@bl AS VARCHAR(10)) + '进程号,其执行的SQL语法如下'
 else
            select '进程号SPID:'+ CAST(@spid AS VARCHAR(10))+ '被' + '进程号SPID:'+ CAST(@bl AS VARCHAR(10)) +'阻塞,其当前进程执行的SQL语法如下'
 DBCC INPUTBUFFER (@bl )
end

-- 循环指针下移
set @intCounter = @intCounter + 1
end


drop table #tmp_lock_who

return 0
end