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

后端 未结 1 1746
-上瘾入骨i
-上瘾入骨i 2021-01-17 15:32

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

CREATE TABLE \"EVALUATION\" (
    \"EVALUATION_ID\" NU         


        
相关标签:
1条回答
  • 2021-01-17 16:33

    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.

    0 讨论(0)
提交回复
热议问题