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.

相关推荐
墨子夕3 小时前
创新的潮汐——从科学发现到资本周期的百年规律(第二卷)
大数据·数据库·人工智能
Y3815326623 小时前
印度电商数据采集教程:用 SerpBase 查 Flipkart/Myntra/Ajio 商品(附代码)
数据库·python
企业数字化笔记3 小时前
多租户配额怎么控制?用量口径、并发预留与超额处理的实现方法
java·数据库·spring boot
roman_日积跬步-终至千里4 小时前
【数据Agent论文·查询与语义|06】RAT-SQL:怎样把问题、表和字段真正关联起来?
数据库·sql·数据分析
盟接之桥4 小时前
盟接之桥谈线束数字化-按单入按单出:线束企业库存管理的破局之道
大数据·前端·网络·数据库·人工智能·制造
Nturmoils4 小时前
数据集成软件 KFS:多套业务库汇聚时,先把来源和口径理清
数据库
麦壳饼4 小时前
SonnetDB:批量写入的大小、背压与刷新策略
数据库·sonnetdb
weixin_460443565 小时前
Java+Linux私有化训考平台:服务、数据库与终端部署结构解析
java·linux·数据库·私有化部署·企业培训考试系统·企业考试系统
编程火箭车5 小时前
MySQL 拥抱 AI:向量、RAG、AutoML 全进了数据库
数据库·mysql·ai编程·向量数据库·rag·automl·mysql9
用户8662978480086 小时前
KingbaseES 中文乱码、排序不对?区域和字符集的问题,一次说清
数据库