同时多个事务内部修改表记录,怎么样避免死锁?

事务1
begin transaction
update t set count= count +1 where id=A
update t set count=cunt+1 where id=b
end transaction

事务2
begin transaction
update t set count= count +1 where id=B
update t set count= count +1 where id=A
end transaction

阅读 4.3k
1 个回答

正确方式,进行将update语句更加id排序。比如永远先更新A,然后更新B

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题