oracle 和sql server 查询数据时锁的区别

oracle:

Summary of Locking Behavior

The database maintains several different types of locks, depending on the operation that acquired the lock.

In general, the database uses two types of locks: exclusive locks and share locks. Only one exclusive lock can be obtained on a resource such as a row or a table, but many share locks can be obtained on a single resource.

Locks affect the interaction of readers and writers. A reader is a query of a resource, whereas a writer is a statement modifying a resource. The following rules summarize the locking behavior of Oracle Database for readers and writers:

  • A row is locked only when modified by a writer.

    When a statement updates one row, the transaction acquires a lock for this row only. By locking table data at the row level, the database minimizes contention for the same data. Under normal circumstances[Foot 1](#Foot 1) the database does not escalate a row lock to the block or table level.

  • A writer of a row blocks a concurrent writer of the same row.

    If one transaction is modifying a row, then a row lock prevents a different transaction from modifying the same row simultaneously.

  • A reader never blocks a writer.

    Because a reader of a row does not lock it, a writer can modify this row. The only exception is a SELECT ... FOR UPDATE statement, which is a special type of SELECT statement that does lock the row that it is reading.

  • A writer never blocks a reader.

    When a row is being changed by a writer, the database uses undo data to provide readers with a consistent view of the row.

SQL SERVER:

Shared Locks

Shared locks are acquired automatically by SQL Server when data is read. Shared locks can be

held on a table, a page, an index key, or an individual row. Many processes can hold shared

locks on the same data, but no process can acquire an exclusive lock on data that has a shared

lock on it (unless the process requesting the exclusive lock is the same process as the one

holding the shared lock). Normally, shared locks are released as soon as the data has been

read, but you can change this by using query hints or a different transaction isolation level.

相关推荐
竹枝溪7 分钟前
MySQL进阶:约束、多表设计、多表查询与事务
java·数据库·mysql·事务·子查询·acid·多表查询
weixin_4316004435 分钟前
NestJS 入门(9):连上数据库,SQL 写在哪?
数据库·后端·sql·学习·nest.js
math_hongfan1 小时前
一对多的数据库姻缘:ArkTS 为鸿蒙订单设计外键与明细表
数据库·华为·harmonyos
城管不管1 小时前
MySQL 慢查询完整排查
java·服务器·jvm·数据库·mysql·spring·面试
XLYcmy1 小时前
PDF论文处理器 - 功能总结
数据库·python·pdf·csv·pymupdf·dify·文本分割
树码小子1 小时前
MySQL 的事务隔离级别(重点面试题)
数据库·mysql
01_ice1 小时前
MySQL表的约束
数据库·sql·mysql
北漂燕郊杨哥2 小时前
Win11 环境下 phpStudy 安装 Redis 最新版,并为 PHP 8.5.9(NTS)配置 redis 扩展
数据库·redis·php
2603_9651481110 小时前
如何解析JSON数据?API返回的商品信息处理教程
开发语言·数据库·python·自动化·json·api
ltl11 小时前
RocksDB 经典故障排查:L0、compaction 与 write stall
数据库