如何做到这样的效果?

fffddd 2006-04-24 07:23:38
Microsoft OLE DB Provider for SQL Server 错误 '80004005'

事务(进程 ID 132)与另一个进程已被死锁在 lock 资源上,且该事务已被选作死锁牺牲品。请重新运行该事务。

csdn有时候会出现这样的提示。不知道是怎么实现的。
...全文
727 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
ALLEN625314 2006-09-26
  • 打赏
  • 举报
回复
邹老大都出来了...我们就不说话了
akuzou 2006-09-22
  • 打赏
  • 举报
回复
值得学习
wisdomone 2006-09-22
  • 打赏
  • 举报
回复
up
擒兽 2006-09-19
  • 打赏
  • 举报
回复
mark
koposo 2006-09-18
  • 打赏
  • 举报
回复
mark
guan0616 2006-09-18
  • 打赏
  • 举报
回复
谢谢 我也看了一遍
being21 2006-08-04
  • 打赏
  • 举报
回复
标记+接分
!!!
xjchen 2006-08-04
  • 打赏
  • 举报
回复
标记+接分
yanguangyun 2006-07-31
  • 打赏
  • 举报
回复
检查一下看有没有反向操作.
fffddd 2006-07-28
  • 打赏
  • 举报
回复
还是没明白。老大能不能再详细说说。

--同时执行,系统会检测出死锁,并中止进程


我的sql 2000里经常出现死锁,怎么我的系统不会检测出死锁并中止进程呢?
顺子 2006-06-14
  • 打赏
  • 举报
回复
分点分给我
fffddd 2006-06-13
  • 打赏
  • 举报
回复
谢谢老大。我实验了之后来结贴。
nate_liu 2006-06-12
  • 打赏
  • 举报
回复
作個記號﹗
zjcxc 2006-06-12
  • 打赏
  • 举报
回复
--设tb(A,B,C)
create table #tb(A varchar(2),B varchar(2),C varchar(2))
insert into #tb
select 'a1','b1','c1'
union all select 'a2','b2','c2'
union all select 'a3','b3','c3'

--1)排它锁
--在第一个连接中执行以下语句
begin tran
update #tb
set A='aa'
where B='b2'
waitfor delay '00:00:3' --等待3秒
commit tran

--在第二个连接中执行以下语句
begin tran
select * from #tb
where B='b2'
commit tran
--若同时执行上述两个语句,则select查询必须等待update执行完毕才能执行即要等待30秒

--2)共享锁
--在第一个连接中执行以下语句
begin tran
select * from #tb holdlock --holdlock人为加锁
where B='b2'
waitfor delay '00:00:3' --等待3秒
commit tran

--在第二个连接中执行以下语句
begin tran
select A,C from #tb
where B='b2'
update #tb
set A='aa'
where B='b2'
commit tran
--若同时执行上述两个语句,则第二个连接中的select查询可以执行
--而update必须等待第一个连接中的共享锁结束后才能执行 即要等待30秒

--3)死锁
--增设tb2(D,E)
create table #tb2(D varchar(2),E varchar(2))
insert into #tb2
select 'd1','e1'
union all select 'd2','e2'

--在第一个连接中执行以下语句
begin tran
update #tb
set A='aa'
where B='b2'
waitfor delay '00:00:5'
update #tb2
set D='d5'
where E='e1'
commit tran

--在第二个连接中执行以下语句
begin tran
update #tb2
set D='d5'
where E='e1'
waitfor delay '00:00:3'
update #tb
set A='aa'
where B='b2'
commit tran

--删除临时表
drop table #tb,#tb2

--同时执行,系统会检测出死锁,并中止进程
/*-------------------------------------------------------------
SET IMPLICIT_TRANSACTIONS ON --用户每次必须显式提交或回滚。否则当用户断开连接时,
--事务及其所包含的所有数据更改将回滚

SET IMPLICIT_TRANSACTIONS OFF --自动提交模式。在自动提交模式下,如果各个语句成功
--完成则提交。
------------------------------------------------------------------------*/

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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