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?
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.
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.
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:
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.
EDIT:
The question is rather why to use obvious keyword when it is turn on by default:
I would say:
This is the same category as:
CREATE TABLE tab(col INT NULL)
Why do we use NULL
if column is nullable by default.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With