1
select * from TTable1 for update
锁定表的所有行,只能读不能写
2
select * from TTable1 where pkid = 1 for update
只锁定pkid=1的行
3
select * from Table1 a join Table2 b on a.pkid=b.pkid for update
锁定两个表的所有记录
4
select * from Table1 a join Table2 b on a.pkid=b.pkid where a.pkid = 10 for update
锁定两个表的中满足条件的行
5.
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
本文详细介绍了使用SQL语句进行数据锁定的方法,包括针对单表及多表的不同锁定方式。通过具体的示例,展示了如何精确控制数据库中数据的访问权限,确保数据的一致性和事务的正确执行。

被折叠的 条评论
为什么被折叠?



