Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I would like to know what's the advantage 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 is just to enable something that has been previously disabled?

like image 648
Lombas Avatar asked Oct 19 '15 15:10

Lombas


People also ask

What does ENABLE mean in oracle?

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.

What is keyword in Oracle SQL?

Oracle SQL keywords are not reserved. However, Oracle uses them internally in specific ways. Therefore, if you use these words as names for objects and object parts, then your SQL statements may be more difficult to read and may lead to unpredictable results.


1 Answers

Constraint doc:

enter image description here

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.

like image 138
Lukasz Szozda Avatar answered Sep 25 '22 06:09

Lukasz Szozda