一、for update 功能(锁住表和锁住符合条件的行)
- select * from TTable1 for update 锁定表的所有行,只能读不能写
- select * from TTable1 where pkid = 1 for update 只锁定pkid=1的行
- select * from Table1 a join Table2 b on a.pkid=b.pkid for update 锁定两个表的所有记录
- select * from Table1 a join Table2 b on a.pkid=b.pkid where a.pkid = 10 for update 锁定两个表的中满足条件的行
- select * from Table1 a join Table2 b on a.pkid=b.pkid where a.pkid = 10 for update of a.pkid 只锁定Table1中满足条件的行
for update 是把所有的表都锁点 for update of 根据of 后表的条件锁定相对应的表
二、for update 和 for update nowait区别(前者阻塞其他事务,后者拒绝其他事务)
for update
锁住表或者锁住行,只允许当前事务进行操作(读写),其他事务被阻塞,直到当前事务提交或者回滚,被阻塞的事务自动执行
for update nowait
锁住表或者锁住行,只允许当前事务进行操作(读写),其他事务被拒绝,事务占据的statement连接也会被断开