在 oracle 数据库语句中使用 ENABLE 关键字的原因/用处是什么
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33217761/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What's the reason / usefulness is to use ENABLE keyword in oracle database statements
提问by Lombas
I would like to know what's the advantage or usefulness of using ENABLE keyword, in statements like:
我想知道在以下语句中使用 ENABLE 关键字有什么好处或用处:
CREATE TABLE "EVALUATION" (
"EVALUATION_ID" NUMBER(20, 0) NOT NULL ENABLE,
OR
或者
ALTER TABLE "EVALUATION"
ADD CONSTRAINT("EVALUATION_FK")
FOREIGN KEY ("CREW_ID")
REFERENCES "CREW" ("CREW_ID") ENABLE;
For what I read in the documentation, ENABLE
is on by default.
对于我在文档中读到的内容,ENABLE
默认情况下是打开的。
Could I assume it is just to enable something that has been previously disabled?
我可以假设它只是为了启用以前禁用的东西吗?
回答by Lukasz Szozda
CREATE TABLE "EVALUATION" (
"EVALUATION_ID" NUMBER(20, 0) NOT NULL ENABLE,
ENABLE/DISABLE
indicates that constraint is on or off. By default ENABLE
is used.
ENABLE/DISABLE
表示约束打开或关闭。默认ENABLE
使用。
ENABLE ClauseSpecify ENABLE if you want the constraint to be applied to the data in the table.
DISABLE ClauseSpecify DISABLE to disable the integrity constraint. Disabled integrity constraints appear in the data dictionary along with enabled constraints. If you do not specify this clause when creating a constraint, Oracle automatically enables the constraint.
ENABLE 子句如果您希望将约束应用于表中的数据,请指定 ENABLE。
DISABLE 子句指定 DISABLE 以禁用完整性约束。禁用的完整性约束与启用的约束一起出现在数据字典中。如果在创建约束时不指定该子句,Oracle 会自动启用该约束。
Constraints are used to ensure data integrity, but there are scenarios we may need to disable them.
约束用于确保数据完整性,但在某些情况下我们可能需要禁用它们。
Disabling Constraints
To enforce the rules defined by integrity constraints, the constraints should always be enabled. However, consider temporarily disabling the integrity constraints of a table for the following performance reasons:
When loading large amounts of data into a table
When performing batch operations that make massive changes to a table (for example, changing every employee's number by adding 1000 to the existing number)
When importing or exporting one table at a time
In all three cases, temporarily disabling integrity constraints can improve the performance of the operation, especially in data warehouse configurations.
It is possible to enter data that violates a constraint while that constraint is disabled. Thus, you should always enable the constraint after completing any of the operations listed in the preceding bullet list.
Efficient Use of Integrity Constraints: A Procedure
Using integrity constraint states in the following order can ensure the best benefits:
Disable state.
Perform the operation (load, export, import).
Enable novalidate state.
Some benefits of using constraints in this order are:
No locks are held.
All constraints can go to enable state concurrently.
Constraint enabling is done in parallel.
Concurrent activity on table is permitted.
禁用约束
要强制执行完整性约束定义的规则,应始终启用约束。但是,出于以下性能原因,请考虑暂时禁用表的完整性约束:
将大量数据加载到表中时
执行对表进行大量更改的批处理操作时(例如,通过在现有编号上加 1000 来更改每个员工的编号)
一次导入或导出一张表时
在所有三种情况下,暂时禁用完整性约束都可以提高操作性能,尤其是在数据仓库配置中。
当约束被禁用时,可以输入违反约束的数据。因此,在完成上述项目符号列表中列出的任何操作后,您应该始终启用约束。
有效使用完整性约束:一个过程
按以下顺序使用完整性约束状态可以确保获得最佳收益:
禁用状态。
执行操作(加载、导出、导入)。
启用 novalidate 状态。
按此顺序使用约束的一些好处是:
没有锁被持有。
所有约束都可以同时进入启用状态。
约束启用是并行完成的。
允许在桌子上进行并发活动。
EDIT:
编辑:
The question is rather why to use obviouskeyword when it is turn on by default:
问题是为什么在默认情况下打开时使用明显的关键字:
I would say:
我会说:
- For clarity (Python EIBTI rule Explicit Is Better Than Implicit)
- For completness
- Personal taste and/or coding convention
- 为了清楚起见(Python EIBTI 规则显式优于隐式)
- 为了完整性
- 个人品味和/或编码约定
This is the same category as:
这与以下类别相同:
CREATE TABLE tab(col INT NULL)
Why do we use NULL
if column is nullable by default.
为什么我们使用NULL
if 列默认可以为空。