oracle lock 07 - DDL Locks

DDL Locks

A data dictionary (DDL) lock protects the definition of a schema object while an ongoing DDL operation acts on or refers to the object. Only individual schema objects that are modified or referenced are locked during DDL operations. The database never locks the whole data dictionary.

Oracle Database acquires a DDL lock automatically on behalf of any DDL transaction requiring it. Users cannot explicitly request DDL locks. For example, if a user creates a stored procedure, then Oracle Database automatically acquires DDL locks for all schema objects referenced in the procedure definition. The DDL locks prevent these objects from being altered or dropped before procedure compilation is complete.

Exclusive DDL Locks

An exclusive DDL lock prevents other sessions from obtaining a DDL or DML lock. Most DDL operations, except for those described in "Share DDL Locks", require exclusive DDL locks for a resource to prevent destructive interference with other DDL operations that might modify or reference the same schema object. For example, DROP TABLE is not allowed to drop a table while ALTER TABLE is adding a column to it, and vice versa.

Exclusive DDL locks last for the duration of DDL statement execution and automatic commit. During the acquisition of an exclusive DDL lock, if another DDL lock is held on the schema object by another operation, then the acquisition waits until the older DDL lock is released and then proceeds.

Share DDL Locks

A share DDL lock for a resource prevents destructive interference with conflicting DDL operations, but allows data concurrency for similar DDL operations.

For example, when a CREATE PROCEDURE statement is run, the containing transaction acquires share DDL locks for all referenced tables. Other transactions can concurrently create procedures that reference the same tables and acquire concurrent share DDL locks on the same tables, but no transaction can acquire an exclusive DDL lock on any referenced table.

A share DDL lock lasts for the duration of DDL statement execution and automatic commit. Thus, a transaction holding a share DDL lock is guaranteed that the definition of the referenced schema object remains constant during the transaction.

Breakable Parse Locks

A parse lock is held by a SQL statement or PL/SQL program unit for each schema object that it references. Parse locks are acquired so that the associated shared SQL area can be invalidated if a referenced object is altered or dropped. A parse lock is called a breakable parse lock because it does not disallow any DDL operation and can be broken to allow conflicting DDL operations.

A parse lock is acquired in the shared pool during the parse phase of SQL statement execution. The lock is held as long as the shared SQL area for that statement remains in the shared pool.

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
MySQL是一种开源的关系型数据管理系统,它支持多种操作系统,并且广泛应用于Web应用程序的后端数据存储。MySQL的DDL(Data Definition Language)是用于定义和管理数据库结构的基础操作。 以下是MySQL中DDL的基础操作: 1. 创建数据库:使用CREATE DATABASE语句可以创建一个新的数据库。例如,CREATE DATABASE mydatabase; 2. 删除数据库:使用DROP DATABASE语句可以删除一个已存在的数据库。例如,DROP DATABASE mydatabase; 3. 创建表:使用CREATE TABLE语句可以创建一个新的数据表。在CREATE TABLE语句中,需要指定表名和表的列及其属性。例如,CREATE TABLE mytable (id INT, name VARCHAR(50)); 4. 删除表:使用DROP TABLE语句可以删除一个已存在的数据表。例如,DROP TABLE mytable; 5. 修改表结构:使用ALTER TABLE语句可以修改已存在的数据表的结构,包括添加、修改和删除列等操作。例如,ALTER TABLE mytable ADD COLUMN age INT; 6. 添加主键:使用ALTER TABLE语句可以为数据表添加主键约束,以确保每行数据的唯一性。例如,ALTER TABLE mytable ADD PRIMARY KEY (id); 7. 添加外键:使用ALTER TABLE语句可以为数据表添加外键约束,以确保与其他表的关联完整性。例如,ALTER TABLE mytable ADD FOREIGN KEY (customer_id) REFERENCES customers(id); 8. 创建索引:使用CREATE INDEX语句可以为数据表创建索引,以提高查询性能。例如,CREATE INDEX idx_name ON mytable (name); 这些是MySQL中DDL的基础操作,通过这些操作可以定义和管理数据库的结构。如果你有更具体的问题或者需要了解更多高级的DDL操作,请告诉我。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

历史五千年

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值