死锁的问题

hlh2002 2003-08-20 03:29:26
如何在存储过程中判断表的死锁以及如何解决???
...全文
23 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
hlh2002 2003-08-20
  • 打赏
  • 举报
回复
谢谢各位朋友。
不过我想解决的问题是表级的死锁,而不是数据库一级的??
直接kill会造成数据的丢失吗?
hlh2002 2003-08-20
  • 打赏
  • 举报
回复
谢谢以上的朋友。
不过我想知道的是表一级的死锁问题,而不是数据库一级的?
caiyunxia 2003-08-20
  • 打赏
  • 举报
回复
修改如下
create proc killspid (@dbname varchar(20))
as
begin
declare @sql nvarchar(500)
declare @spid int
set @sql='declare getspid cursor for
select blocked from sysprocesses where dbid=db_id('''+@dbname+''') and blocked >0'
exec (@sql)
open getspid
fetch next from getspid into @spid
while @@fetch_status < >-1
begin
exec('kill '+rtrim(@spid))
fetch next from getspid into @spid
end
close getspid
deallocate getspid
end

--用法
use master
exec killspid '数据库名'
caiyunxia 2003-08-20
  • 打赏
  • 举报
回复
select blocked from sysprocesses where blocked >0
表示引起LOCK的进程号
KILL次进程号即可
caiyunxia 2003-08-20
  • 打赏
  • 举报
回复
select spid from sysprocesses
中是所有的存关于运行在 Microsoft® SQL Server™ 上的进程的信息
CrazyFor(太阳下山明朝依旧爬上来) 的方法回KILL没死锁的进程
lht0530 2003-08-20
  • 打赏
  • 举报
回复
占座学习
chao778899 2003-08-20
  • 打赏
  • 举报
回复
xuexi
zjcxc 2003-08-20
  • 打赏
  • 举报
回复
判断死锁?

新问题,占座学习.
CrazyFor 2003-08-20
  • 打赏
  • 举报
回复
create proc killspid (@dbname varchar(20))
as
begin
declare @sql nvarchar(500)
declare @spid int
set @sql='declare getspid cursor for
select spid from sysprocesses where dbid=db_id('''+@dbname+''')'
exec (@sql)
open getspid
fetch next from getspid into @spid
while @@fetch_status < >-1
begin
exec('kill '+rtrim(@spid))
fetch next from getspid into @spid
end
close getspid
deallocate getspid
end

--用法
use master
exec killspid '数据库名'

22,207

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧