下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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年一建《机电》真题及答案解析-完整版
- 绿化苗木起挖施工方案及工艺方法
- 化工工艺设备安装与管道安装施工方案
- 水生产处理工(初级工)理论考试题库附答案(新版)
- 产房ICD故障应急演练脚本
- 循环水岗位考试题库(附答案)
- 卸料平台坠落应急预案
- 围挡喷淋系统施工工艺
- 大学生心理健康教育理论知识考核试题及答案
- 2026年江苏省江阴市高二化学下册期末考试模拟检测卷及参考答案【培优B卷】
- 2026年合集2026春人教PEP版(新教材)小学英语四年级下册(全册)各单元知识点梳理新版
- 2026江苏苏州市健康养老产业发展集团有限公司下属子公司招聘44人(第一批)笔试历年参考题库附带答案详解
- 2026年妇联家庭教育指导服务课件
- 2026年高压电工证考试题库(答案及解析)
- 2026年宁夏回族自治区银川市重点学校小升初英语考试试题及答案
- 七下数学必刷题目及答案
- 养殖鲈鱼技术培训课件
- 全国消防面试题目及答案
- 《工业机器人操作与编程ABB》-04项目四 ABB机器人程序编写
- 矿井智能通风课件
- 教研员结构化面试试题及答案
评论
0/150
提交评论