What's the reason / usefulness is to use ENABLE keyword in oracle database statements

若如初见. 提交于 2019-12-07 05:13:37

问题


I would like to know what's the advantadge or usefulness of using ENABLE keyword, in statements like:

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.

Could I assume it's just to enable something that has been previously disabled?


回答1:


Constraint doc:

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 Clause Specify ENABLE if you want the constraint to be applied to the data in the table.

DISABLE Clause Specify 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.

Constraints are used to ensure data integrity, but there are scenarios we may need to disable them.

Managing Integrity:

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:

  1. Disable state.

  2. Perform the operation (load, export, import).

  3. 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.

EDIT:

The question is rather why to use obvious keyword when it is turn on by default:

I would say:

  1. For clarity (Python EIBTI rule Explicit Is Better Than Implicit)
  2. For completness
  3. Personal taste and/or coding convention

This is the same category as:

CREATE TABLE tab(col INT NULL)

Why do we use NULL if column is nullable by default.



来源:https://stackoverflow.com/questions/33217761/whats-the-reason-usefulness-is-to-use-enable-keyword-in-oracle-database-state

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!