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.

相关推荐
盟接之桥9 分钟前
线束数字化--先进先出为什么总是停留在纸面上?
大数据·网络·数据库·人工智能·制造·ai编程
adinnet20261 小时前
预算管控:预算执行与偏差问数
大数据·数据库
Omics Pro3 小时前
Cell封面|衰老生物学开源AI工具包
数据库·人工智能·算法·机器学习·自然语言处理
IT枫斗者枫哥10 小时前
MyBatis一对多分页:LIMIT 20,为什么凑不齐20个订单?
java·数据库
Y0010 小时前
PostgreSQL 的锁:为什么你的 ALTER TABLE 会卡住,以及怎么查
数据库·postgresql
灰原喜欢柯南11 小时前
OceanBase 运维管理知识点——OCP 监控、诊断与变更控制
数据库·oceanbase
码农-00411 小时前
Springboot 集成 Ehcache操作数据库显示SQL语句设置
数据库·spring boot·sql
仍然.11 小时前
Redis---事务
数据库·redis
oradh11 小时前
Oracle 执行计划的阅读方法(二叉树结构来理解和阅读)
数据库·oracle·执行计划的阅读方法
SelectDB11 小时前
Doris 向量检索上线踩坑记录:七个排查现场与可直接复制的命令
大数据·数据库·数据分析