gpt4 book ai didi

sql-server - 锁问题 - 'U' 锁与 'X' 锁

转载 作者:行者123 更新时间:2023-12-03 09:30:22 24 4
gpt4 key购买 nike

我有几个关于更新 (U) 锁和排他 (X) 锁的问题。

1)当资源即将更新时,我是否正确地将“X”锁放在资源上?

2)我对U锁有点模糊。当读取资源并且 SQL Server 认为它可能需要稍后更新资源时应用 U 锁,我是否正确?如果这是正确的,是否只有在事务上下文中进行读取时才会应用“U”锁?我想我试图了解在什么情况下 SQL Server 认为它可能需要稍后更新它现在刚刚读取的行。

谢谢 - 兰迪

最佳答案

1) Am I correct that an 'X' lock is put on a resource when the resource is about to get updated?



是的。

2) I'm a little fuzzy on U locks. Am I correct that a U lock is applied when a resource is read and SQL Server thinks it might need to update the resource later? If this is correct, would a 'U' lock only get applied when a read is being done within the context of a transaction? I guess I'm trying to understand under what circumstances SQL Server thinks it might need to update later a row it just read now.


U锁与读锁兼容,但彼此不兼容, X锁与读锁不兼容。
U锁由 DML 放置查询 ( UPDATE , DELETE , MERGE ) 而 扫描 表行(尚未决定更新),而 X当决定更新行时,就会放置锁。

READ COMMITTED隔离模式,更新锁在记录被评估为保持原样后解除,在更高的隔离模式下,它们会一直保留到事务结束。

关于sql-server - 锁问题 - 'U' 锁与 'X' 锁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2812507/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com