下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、sybase:锁、事务、并发、死锁、测试测试总结:1、在事务中,要更新的表不是事务开始时就全部锁定了,只是在用到时才锁定,等提交时才 释放。这就要注意一个问题,在事务中,前面查询的数据,在后面该值可能已经改变了。2、事务并发, 并相互有竞争,但没有死锁时,两个都成功。3、事务并发,并相互有竞争,有死锁时,只有一个成功, 最后发现死锁的事务才可成功。测试环境:数据库版本:sybase_win_12.5.2sql执行程序:sqladv1、先建2个测试表tA,tB;插入测试数据if exists (select 1from sysobjectswhere id = object_id(tA)and
2、type = U) Sdrop table tAgoif exists (select 1from sysobjectswhere id = object_id(tB)and type = U)drop table tB go /*=*/ /* Table: t A*/ copyright Sqlclub /*=*/ create table tA ( namechar(20)null,priceintdefault 0 null,) go /*=*/ /* Table: t B*/本文来自Sqlclub/*=*/ create table tB (namechar(20)null,salep
3、riceintdefault 0 null,)go ALTER TABLE tA LOCK DATAROWSALTER TABLE tB LOCK DATAROWSgo insert into tA(name, price) values (book,20) insert into tB(name, saleprice) values (book,10)go查询结果result:select * from tAselect * from tB nameprice Sqlclubbook20 namesalepricebook10测试用例1:事务和别的sql发生并发的情况1:测试代码:事务代码
4、tran1: begin tranupdate tA set price=price+100 where name=bookwaitfor delay 00:00:05update tB set saleprice=saleprice+100 where name=bookcommit tran 并发代码 code1:update tA set price=price+20000 where name=book测试步骤: 内容来自 S执行tran1,然后马上执行并发代码code1测试结果:tran1执行完成后code1也执行完成了。tran1:(1 row affected)(1 row af
5、fected) code1:(1 row affected) result:namepricebook20120 namesalepricebook110测试说明,在事务处理成功后,并发才能执行。copyright Sqlclub测试用例2:事务和别的sql发生并发的情况2:测试代码:事务代码 tran1: begin tranupdate tA set price=price+100 where name=bookwaitfor delay 00:00:05update tB set saleprice=saleprice+100 where name=bookcommit tran 并发代
6、码 code2:update tB set saleprice=saleprice+10000 where name=book测试步骤:执行tran1,然后马上执行并发代码code2测试结果:code2马上能成功,tran1也能按时执行成功。tran1:(1 row affected)(1 row affected) code2:(1 row affected) result:namepricebook120 namesaleprice 本文来自 Sqlclubbook10110测试说明,并发代码在事务没有锁定相关记录时,还是可以修改的。用例1和用例2说明,在事务中,要更新的表不是事务开始时就
7、全部锁定了,只是在用到时才锁定,等提交时 才释放。 这就要注意一个问题,在事务中,前面查询的数据,在后面该值可能已经改变了。测试用例3: 事务和事务发生并发的情况1: 测试代码: 事务代码 tran1: begin tran update tA set price=price+100 where name=book waitfor delay 00:00:05 update tB set saleprice=saleprice+100 where name=book commit tran 事务代码 tran2: begin tran update tB set saleprice=salep
8、rice+10000 where name=book Supdate tA set price=price+20000 where name=book commit tran测试步骤: 执行tran1,然后马上执行tran2测试结果: tran1执行完成后tran2也执行完成了,但tran2出错了。 tran1: (1 row affected) (1 row affected) tran2: (1 row affected) Server Message: Number 1205, Severity 13 Server ONLINEDB, Line 5:Your server command
9、 (family id #0, process id #17) encountered a deadlock situation. Please rerun your command. result: namepricebook120 namesaleprice copyright Sqlclubbook110测试说明,事务并发,并相互有竞争,但没有死锁时,两个都成功。测试用例4:事务和事务发生并发的情况1:测试代码:事务代码 tran1: begin tranupdate tA set price=price+100 where name=bookwaitfor delay 00:00:05
10、update tB set saleprice=saleprice+100 where name=bookcommit tran 事务代码 tran3: begin tranupdate tA set price=price+20000 where name=bookupdate tB set saleprice=saleprice+10000 where name=bookcommit tran测试步骤:执行tranl,然后马上执行tran3测试结果:tranl执行完成后tran3也执行完成了。tranl:(1 row affected) S(1 row affected) tran3:(1
11、 row affected)(1 row affected) result:namepricebook20120 namesalepricebook10110测试说明,事务并发,并相互有竞争,但没有死锁时,两个都成功。测试用例5:S事务和事务发生并发的情况2:测试代码:事务代码 tran1: begin tranupdate tA set price=price+100 where name=bookwaitfor delay 00:00:05update tB set saleprice=saleprice+100 where name=bookcommit tran 事务代码 tran4:
12、 begin tranupdate tB set saleprice=saleprice+10000 where name=bookupdate tA set price=price+20000 where name=bookcommit tran 测试步骤:执行tran1,然后马上执行tran4测试结果:tran1执行完成后tran4也执行完成了,但tran1完成时间是12秒。tran1:(1 row affected)(1 row affected) tran4:(1 row affected)Server Message: Number 1205, Severity 13Server O
13、NLINEDB, Line 3:Your server command (family id #0, process id #17) encountered a deadlock situation. Please rerun your command. result:nameprice copyright Sqlclubbook120 namesalepricebook110测试说明,事务并发,并相互有竞争,有死锁时,只有一个成功,最后发现死锁的事务才可成功。测试用例6:事务和事务发生并发的情况3:测试代码:事务代码 tranl: begin tranupdate tA set price=
14、price+100 where name=bookSqlclub学习社区waitfor delay 00:00:05update tB set saleprice=saleprice+100 where name=book commit tran 事务代码 tran5: begin tranupdate tB set saleprice=saleprice+10000 where name=book waitfor delay 00:00:10update tA set price=price+20000 where name=book commit tran测试步骤:执行tran1,然后马上
15、执行tran5测试结果:tran1执行完成后tran5也执行完成了,但tran1完成时间是12秒。tran1:(1 row affected)Server Message: Number 1205, Severity 13Server ONLINEDB, Line 5:Your server command (family id #0, process id #15) encountered a deadlock situation. Please rerun your command. tran5: (1 row affected) (1 row affected) result: name
16、price内容来自Sbook20020 namesalepricebook10010测试说明,事务并发,并相互有竞争,有死锁时,只有一个成功,最后发现死锁的事务才可成功。测试用例7:事务和事务发生并发的情况4:测试代码:事务代码 tran1: begin tranupdate tA set price=price+100 where name=bookwaitfor delay 00:00:05update tB set saleprice=saleprice+100 where name=bookcommit tran 事务代码 tran6: begin tranSqlclub update tA set price=price+20000 where name=book waitfor delay 00:00:10update tB set saleprice=salep
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026初中历史教资面试通史题库及解析
- 办公环境巡检流程SOP-含巡检路线图和记录表2版
- 2026年护士执业《基础护理学》模拟试题(含答案)
- 2026年公务员考试申论热点分析专项训练试题卷
- 2026年医师资格考试内科常见病诊断全真试题试卷
- 2026年事业单位文旅专业考试单套试卷文旅政策高频考点
- 2026秋小学粤教粤科版版科学五年级上册第1单元 我们的身体《第6课 健康生活》教学设计
- 2026秋学期小学统编版道德与法治五年级(新教材)上册教学计划附进度表
- 2026中考6篇深奥高阶满分作文(必背高质量版)
- JAVA期末试题及答案
- 徕卡相机LEICA V-Lux 4 中文使用说明书
- 华兴数控WA-32XTA用户手册
- 中长导管的置管及护理
- (正式版)HGT22820-2024化工安全仪系统工程设计规范
- 冬季农业种植项目合作书
- 石墨调控(im)SiC-Cu复合材料工艺及性能研究
- 电力公司物业管理服务方案投标文件(技术方案)
- 学校传染病和突发公共卫生事件处理流程图
- 施工现场交通安全培训
- 家庭成员及主要社会关系情况表
- 安全教育培训课件体育运动安全与防范
评论
0/150
提交评论