在MySQL中,update user set id=?,name=? where id=? 语句在并发情况下,会出现‘锁’的现象吗?
答案:1 悬赏:70
解决时间 2021-01-24 14:59
- 提问者网友:斑駁影
- 2021-01-23 21:07
在MySQL中,update user set id=?,name=? where id=? 语句在并发情况下,会出现‘锁’的现象吗?
最佳答案
- 二级知识专家网友:动情书生
- 2021-01-23 22:43
update理论上都有锁,只要不死锁,就问题不大
如你在一个事务中
update user where userid=1;
update dept where deptid=2;
commit;
而另一个连接
update dept where deptid=2;
update user where userid=1;
commit;
如果这2个连接同时执行这些语句,就可能死锁。
所以要特别注意update的表的顺序和where 条件的中记录的执行顺序(对参数先排序)
1)
update user set ... where userid=1;
update user set ... where userid=2;
commit
2)
update user set ... where userid=2;
update user set ... where userid=1;
commit
可能死锁
如你在一个事务中
update user where userid=1;
update dept where deptid=2;
commit;
而另一个连接
update dept where deptid=2;
update user where userid=1;
commit;
如果这2个连接同时执行这些语句,就可能死锁。
所以要特别注意update的表的顺序和where 条件的中记录的执行顺序(对参数先排序)
1)
update user set ... where userid=1;
update user set ... where userid=2;
commit
2)
update user set ... where userid=2;
update user set ... where userid=1;
commit
可能死锁
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯