




下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 广东省茂名市2024-2025学年高二下学期期末教学质量监测政治试卷(含答案)
- 2026版名师金典 语文课件29 板块三 专题一 考题研析 任务突破二 第1讲 文言断句题
- 河南零售商户管理办法
- 决策事项督查管理办法
- 渔政执法船舶管理办法
- 供给侧结构性改革解读试题及答案
- 江苏税务举报管理办法
- 江西执法证件管理办法
- 校园预算经费管理办法
- 内河河道清理管理办法
- 企业财务内控管理制度
- 2025以色列与伊朗冲突全面解析课件
- 警察抓捕教学课件
- 2025年农产品质量安全追溯体系在食品安全监管中的应用与改进报告
- 做账实操-渔业行业的账务处理分录实例
- 2025-2030年中国手持三维激光扫描仪行业市场深度分析及发展趋势与投资前景研究报告
- 2025-2030年中国单壁碳纳米管(SWNT)行业市场现状供需分析及投资评估规划分析研究报告
- 新教育 考试试题及答案
- 格力入职考试试题及答案
- 2025年广东珠海市香洲区英语七年级第二学期期末考试试题含答案
- 2024年吉林省长春市中考二模考试地理生物试卷-初中地理
评论
0/150
提交评论