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.

相关推荐
if时光重来8 小时前
kingbase数据库指定数据表自增id重置
数据库·python·sql
jingyucsdn8 小时前
将postgresql结构和数据备份成sql语句
数据库·sql·postgresql
我科绝伦(Huanhuan Zhou)8 小时前
Oracle等待事件:性能诊断与优化的核心指南
数据库·oracle
梦里不知身是客118 小时前
explain分析SQL语句分析sql语句的优劣
java·数据库·sql
程序员zgh8 小时前
SOLID软件设计原则 解析
数据库
TDengine (老段)8 小时前
开放生态破局工业大数据困局:TDengine 的迭代升级与全链路数据自由流动
大数据·数据库·物联网·时序数据库·tdengine·涛思数据
一位代码8 小时前
一些常用的通用 mysql 命令详解及注意事项
数据库·mysql
苏supper9 小时前
DBExportDoc V1.0 For Oracle.doc导出oracle数据库表结构说明文档出错Fatal NI connect error 6413
oracle
曹牧9 小时前
Oracle:五笔码
数据库·oracle