首页 > 应用开发 > IT综合 > Table Locks (TM) (343)

Table Locks (TM) (343)

原创 IT综合 作者:tsinglee 时间:2007-12-10 11:46:55 0 删除 编辑

Table-level locks are primarily used to do concurrency control with concurrent DDL
operations, such as preventing a table from being dropped in the middle of a DML
operation. When a DDL or DML statement is on a table, a table lock is acquired. Table
locks do not affect concurrency of DML operations. For partitioned tables, table locks
can be acquired at both the table and the subpartition level.

A transaction acquires a table lock when a table is modified in the following DML
statements: INSERT, UPDATE, DELETE, SELECT with the FOR UPDATE clause, and
LOCK TABLE. These DML operations require table locks for two purposes: to reserve
DML access to the table on behalf of a transaction and to prevent DDL operations that
would conflict with the transaction. Any table lock prevents the acquisition of an
exclusive DDL lock on the same table and thereby prevents DDL operations that
require such locks. For example, a table cannot be altered or dropped if an
uncommitted transaction holds a table lock for it.

A table lock can be held in any of several modes: row share (RS), row exclusive (RX),
share (S), share row exclusive (SRX), and exclusive (X). The restrictiveness of a table
lock’s mode determines the modes in which other table locks on the same table can be
obtained and held.

1. 当用户进行DML或DDL操作时, 表锁将被获得
或执行 LOCK TABLE 语句时,事务将获得表级锁.
DML语句获取表级锁的目的有两个 :
a. 保证事务能对表进行操作
b. 阻止其他事务中和自身事务有冲突的 DDL 操作执行

3. 表锁的几个模式
RS: 行共享
RX: 行排他
S: 共享
SRX: 共享行排他
X: 排他


来自 “ ITPUB博客 ” ,链接:,如需转载,请注明出处,否则将追究法律责任。

上一篇: Row Locks (TX) (342)
  • 博文量
  • 访问量