论坛首页 Java企业应用论坛

db2 的 select for update 的lock mode

浏览 3320 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2017-10-31  

DB2  for update 没有加排他锁?

 

select  * from table_name where id='xx' for update  (id是主键,具有主键索引)

 

经测试:如上语句并没有给行加U(update)锁,而是S(共享)锁

 

select  * from table_name where id='xx'

select  * from table_name where id='xx' for update

select  * from table_name where id='xx' for update with CS

如上3条语句效果一样,给查询结果加的都是S锁,1个事务查询到结果,另一个事务仍可以对其查询修改

 

select  * from table_name where id='xx' for update with RR

select  * from table_name where id='xx' for update with RS

如上两条,对查询结果加的是U锁,1个事务查询结果未提交,令一个事务无法对其update操作

 

参考:http://blog.chinaunix.net/uid-20313874-id-299469.html

 

论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics