数码资讯
SQLServer锁、互斥锁、共享锁、更新锁、乐观锁、悲观锁分析
分类方法有两种。 (1)从数据库系统的角度 锁分为以下三种类型: 互斥锁(独占锁) The exclusive lock locked resource only allows the program to be used for the lock operation, and any other
选购提示
关注价格、性能、续航、售后和真实使用场景,理性比较后再下单。
分类方法有两种。
(1)从数据库系统的角度
锁分为以下三种类型:
互斥锁(独占锁)
The exclusive lock locked resource only allows the program to be used for the lock operation, and any other operation on it will not be accepted.When the data update command is executed, that is, the INSERT, UPDATE, or DELETE commands, the SQL Server will automatically use an exclusive lock.But when there are other locks on the object, it is not possible to add an exclusive lock to it.The exclusive lock can not be released until the end of the transaction.
共享锁(共享锁)
共享锁锁定资源可以由其他用户读取,但其他用户不能修改它。当选择命令执行时,SQL Server通常是对象上的共享锁锁。当读取共享锁的数据页时,共享锁立即释放。
更新锁(更新锁)
更新锁设置防止死锁。当SQL Server正在准备更新数据,它首先锁定的数据对象的更新锁,数据不能修改,但可以读取。当SQL Server决定更新数据的操作,它会自动更改更新锁独家锁。但当物体上有其他锁,不能锁在更新锁。
(2)从程序员的角度来看
锁分为以下两种类型:
乐观锁(乐观锁)
乐观锁假设在处理数据时,它不需要在应用程序代码中做任何事情,它可以直接锁定记录,也就是说,只依赖数据库来管理锁的工作。
悲观锁(悲观锁)
悲观锁不能跟上数据库系统的自动化管理。它要求程序员直接管理对象上的数据或锁处理,并负责获取、共享和放弃正在使用的数据的任何锁。
(1)从数据库系统的角度
锁分为以下三种类型:
互斥锁(独占锁)
The exclusive lock locked resource only allows the program to be used for the lock operation, and any other operation on it will not be accepted.When the data update command is executed, that is, the INSERT, UPDATE, or DELETE commands, the SQL Server will automatically use an exclusive lock.But when there are other locks on the object, it is not possible to add an exclusive lock to it.The exclusive lock can not be released until the end of the transaction.
共享锁(共享锁)
共享锁锁定资源可以由其他用户读取,但其他用户不能修改它。当选择命令执行时,SQL Server通常是对象上的共享锁锁。当读取共享锁的数据页时,共享锁立即释放。
更新锁(更新锁)
更新锁设置防止死锁。当SQL Server正在准备更新数据,它首先锁定的数据对象的更新锁,数据不能修改,但可以读取。当SQL Server决定更新数据的操作,它会自动更改更新锁独家锁。但当物体上有其他锁,不能锁在更新锁。
(2)从程序员的角度来看
锁分为以下两种类型:
乐观锁(乐观锁)
乐观锁假设在处理数据时,它不需要在应用程序代码中做任何事情,它可以直接锁定记录,也就是说,只依赖数据库来管理锁的工作。
悲观锁(悲观锁)
悲观锁不能跟上数据库系统的自动化管理。它要求程序员直接管理对象上的数据或锁处理,并负责获取、共享和放弃正在使用的数据的任何锁。
声明:本文内容用于数码产品信息整理与选购参考,具体价格、库存、售后政策以官方渠道和电商页面实时信息为准。