永发信息网

在MySQL中,下面update语句会出现‘锁’的现象吗

答案:2  悬赏:70  手机版
解决时间 2021-12-21 02:22
  • 提问者网友:轮囘Li巡影
  • 2021-12-20 16:44
在MySQL中,下面update语句会出现‘锁’的现象吗
最佳答案
  • 五星知识达人网友:佘樂
  • 2021-12-20 17:00
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
可能死锁
全部回答
  • 1楼网友:白昼之月
  • 2021-12-20 18:15
首先你要理解锁的意义,单一的语句执行不存在锁的问题,只有在资源冲突时才有锁的概念。所以单一执行这句话是不会出现锁的现象的。
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯